@
9hills 確實如此.
In [719]: a = range(100000)
In [720]: b = range(100000)
In [721]:
cProfile.run('reduce(lambda x, y: x + y, zip(a, b))')
100003 function calls in 46.933 seconds
Ordered by: standard name
ncalls tottime percall cumtime percall filename:lineno(function)
99999 27.569 0.000 27.569 0.000 <string>:1(<lambda>)
1 0.005 0.005 46.933 46.933 <string>:1(<module>)
1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}
1 19.341 19.341 46.911 46.911 {reduce}
1 0.017 0.017 0.017 0.017 {zip}
In [722]:
cProfile.run('list(itertools.chain(*zip(a, b)))')
3 function calls in 0.022 seconds
Ordered by: standard name
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.014 0.014 0.022 0.022 <string>:1(<module>)
1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}
1 0.008 0.008 0.008 0.008 {zip}