【发布时间】:2014-07-18 13:24:09
【问题描述】:
我正在使用 cProfile 检查过滤器的性能,
cProfile.run("""
s = [range(10000) for i in range(10000)]
filter(None, map(lambda x:x[0], s))""")
20005 function calls in 42.272 seconds
Ordered by: standard name
ncalls tottime percall cumtime percall filename:lineno(function)
1 2.467 2.467 42.272 42.272 <string>:2(<module>)
10000 0.004 0.000 0.004 0.000 <string>:3(<lambda>)
1 0.000 0.000 0.000 0.000 {filter}
1 0.201 0.201 0.205 0.205 {map}
1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}
10001 39.599 0.004 39.599 0.004 {range}
从上面的分析中我观察到过滤器,它调用了一次但没有花费时间,为什么它没有花费时间?
【问题讨论】:
-
filter 在 Python2 和 Python3 上的工作方式不同,那么你在哪个上运行呢?
-
@gnibbler 我用过python2.7
标签: python python-2.7 python-3.x filter