


import gc
import threading
import time

import psutil
import torch







class 							lowerCamelCase__						:






			"""simple docstring"""






			def __init__(				self  ):

						'''simple docstring'''


						UpperCamelCase__       =							psutil.Process()
						UpperCamelCase__       =							False




			def 					snake_case__					(				self  ):

						'''simple docstring'''


						UpperCamelCase__       =							-1

						while True:
									UpperCamelCase__       =							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 					snake_case__					(				self  ):

						'''simple docstring'''


						UpperCamelCase__       =							True
						UpperCamelCase__       =							threading.Thread(target=self.peak_monitor  )
						UpperCamelCase__       =							True
						self.thread.start()







			def 					snake_case__					(				self  ):

						'''simple docstring'''


						UpperCamelCase__       =							False
						self.thread.join()
						return self.cpu_memory_peak



__UpperCamelCase     		=							PeakCPUMemory()
def 							UpperCamelCase_(					)->		List[str]:
			# Time
			UpperCamelCase__       =							{"time": time.time()}

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

			# CPU mem
			UpperCamelCase__       =							psutil.Process().memory_info().rss
			cpu_peak_tracker.start()

			# GPU mem
			for i in range(torch.cuda.device_count()	):
						UpperCamelCase__       =							torch.cuda.memory_allocated(_A	)
			torch.cuda.reset_peak_memory_stats()

			return measures
def 							UpperCamelCase_(					_A :Dict	)->		str:
			# Time
			UpperCamelCase__       =							{"time": time.time() - start_measures["time"]}

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

			# CPU mem
			UpperCamelCase__       =							(psutil.Process().memory_info().rss - start_measures["cpu"]) / 2**20
			UpperCamelCase__       =							(cpu_peak_tracker.stop() - start_measures["cpu"]) / 2**20

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

			return measures







def 							UpperCamelCase_(					_A :Optional[int]					,  _A :int	)->		Union[str, Any]:
			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'''	)
						UpperCamelCase__       =							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'''	)






import requests
from bsa import BeautifulSoup
def 							UpperCamelCase_(					_A :str = "AAPL"	)->		str:
			UpperCamelCase__       =							F'''https://in.finance.yahoo.com/quote/{symbol}?s={symbol}'''
			UpperCamelCase__       =							BeautifulSoup(requests.get(_A	).text					,  "html.parser"	)
			UpperCamelCase__       =							"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}''')


