


'''simple docstring'''






import gc
import threading
import time

import psutil
import torch






class   __snake_case			:







    """simple docstring"""



    def __init__(  self       :    Tuple						)  ->    str:
      lowerCAmelCase_     : List[Any]     =  psutil.Process()
      lowerCAmelCase_     : Optional[Any]     =  False

    def __lowercase  (  self       :    Tuple						)  ->    Any:
      lowerCAmelCase_     : Dict     =  -1

      while True:
        lowerCAmelCase_     : str     =  max(self.process.memory_info().rss       ,		self.cpu_memory_peak						)

        # can't sleep or will not catch the peak right (this comment is here on purpose)
        if not self.peak_monitoring:
          break

    def __lowercase  (  self       :    List[str]						)  ->    Any:
      lowerCAmelCase_     : List[str]     =  True
      lowerCAmelCase_     : Tuple     =  threading.Thread(target=self.peak_monitor						)
      lowerCAmelCase_     : Any     =  True
      self.thread.start()





    def __lowercase  (  self       :    Dict						)  ->    int:
      lowerCAmelCase_     : List[str]     =  False
      self.thread.join()
      return self.cpu_memory_peak







__A   :    Dict											= PeakCPUMemory()







def 							UpperCamelCase_     (       ):
  '''simple docstring'''





  lowerCAmelCase_     : Any     =  {"""time""": time.time()}

  gc.collect()
  torch.cuda.empty_cache()

  # CPU mem
  lowerCAmelCase_     : Dict     =  psutil.Process().memory_info().rss
  cpu_peak_tracker.start()

  # GPU mem
  for i in range(torch.cuda.device_count()   ):
    lowerCAmelCase_     : Optional[Any]     =  torch.cuda.memory_allocated(A__   )
  torch.cuda.reset_peak_memory_stats()

  return measures







def 							UpperCamelCase_     (       A__   :  Optional[int]   ):
  '''simple docstring'''





  lowerCAmelCase_     : List[Any]     =  {"""time""": time.time() - start_measures["""time"""]}

  gc.collect()
  torch.cuda.empty_cache()

  # CPU mem
  lowerCAmelCase_     : List[str]     =  (psutil.Process().memory_info().rss - start_measures["""cpu"""]) / 2**20
  lowerCAmelCase_     : int     =  (cpu_peak_tracker.stop() - start_measures["""cpu"""]) / 2**20

  # GPU mem
  for i in range(torch.cuda.device_count()   ):
    lowerCAmelCase_     : List[str]     =  (torch.cuda.memory_allocated(A__   ) - start_measures[str(A__   )]) / 2**20
    lowerCAmelCase_     : List[Any]     =  (torch.cuda.max_memory_allocated(A__   ) - start_measures[str(A__   )]) / 2**20

  return measures







def 							UpperCamelCase_     (       A__   :  Union[str, Any]				,       A__   :  str   ):
  '''simple docstring'''





  print(f'{description}:'   )
  print(f'- Time: {measures["time"]:.2f}s'   )
  for i in range(torch.cuda.device_count()   ):
    print(f'- GPU {i} allocated: {measures[str(A__   )]:.2f}MiB'   )
    lowerCAmelCase_     : List[str]     =  measures[f'{i}-peak']
    print(f'- GPU {i} peak: {peak:.2f}MiB'   )
  print(f'- CPU RAM allocated: {measures["cpu"]:.2f}MiB'   )
  print(f'- CPU RAM peak: {measures["cpu-peak"]:.2f}MiB'   )







'''simple docstring'''






import requests
from bsa import BeautifulSoup







def 							UpperCamelCase_     (       A__   :  str = "AAPL"   ):
  '''simple docstring'''





  lowerCAmelCase_     : Dict     =  f'https://in.finance.yahoo.com/quote/{symbol}?s={symbol}'
  lowerCAmelCase_     : Optional[Any]     =  BeautifulSoup(requests.get(A__   ).text				,       """html.parser"""   )
  lowerCAmelCase_     : Union[str, Any]     =  """My(6px) Pos(r) smartphone_Mt(6px)"""
  return soup.find("""div"""				,       class_=class_   ).find("""span"""   ).text


if __name__ == "__main__":
  for symbol in "AAPL AMZN IBM GOOG MSFT ORCL".split():
    print(F'''Current {symbol:<4} stock price is {stock_price(symbol):>8}''')



