Python list comprehension vs generator

前端 未结 3 1397
后悔当初
后悔当初 2021-01-07 08:47

I found this question Generators vs List Comprehension performance in Python and instead of cProfile I use timeit.

from timeit import timeit
import cProfile
         


        
3条回答
  •  南方客
    南方客 (楼主)
    2021-01-07 08:54

    The generator version won. The cProfile profiling simply introduced way more overhead for the genexp than the list comprehension, since it has a lot more points where the profiler butts in.

提交回复
热议问题