Yield in Python performances comparison -
i'm reading yield expression , generators in python, approach it's encouraged during huge calculations.
to check that, i've created simple .py script, in order measure time between 1 approach, using yield expression , in memory range built-in class.
here script:
import time def pow(): in range(100000000): yield i*i start_time = time.time() in pow(): res = print('seconds yield: {0}'.format(time.time() - start_time)) start_time = time.time() in range(100000000): res = i*i print('seconds in-memory: {0}'.format(time.time() - start_time))
it's little bit strange behavior, because, i've run script via terminal , results are:
seconds yield: 17.303140878677368 seconds in-memory: 17.322022914886475
i expecting lower value on "yield" approach, in case higher "in memory approach".
i've checked on system monitor if there differences in therm of used ram or cpu, same in case...
...can able explain me why???
thanks.
Comments
Post a Comment