- Home
- Course Detail
regularpython@gmail.com
You are now watching:
Python Generators / of Generator Basic Examples 2
import memory_profiler import time before = memory_profiler.memory_usage() print(before,"Mb") def doctor(patients): result = [] for p in patients: result.append("Patient %s checkup completed.."%(p)) return result patients = range(10000000) t1 = time.clock() status = doctor(patients) for k in status: pass # print(k) t2 = time.clock() after = memory_profiler.memory_usage() print(after,"Mb") print("Extra Memory was taken for execution is {} Mb".format(after[0]-before[0])) print("program execution time is %s Seconds",(t2-t1))
#==========================================With Generators =========================================================== before = memory_profiler.memory_usage() print(before,"Mb") def doctor(patients): for p in patients: yield "Patient %s checkup completed.."%(p) patients = range(10000000) t1 = time.clock() status = doctor(patients) for k in status: pass t2 = time.clock() after = memory_profiler.memory_usage() print(after,"Mb") print("Extra Memory was taken for execution is {} Mb".format(after[0]-before[0])) print("program execution time is %s Seconds",(t2-t1))