本文实例讲述了python中map和列表推导效率比较。分享给大家供大家参考。具体分析如下:
直接来测试代码吧:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# list comprehension and map
import time
def test(f, name):
st = time.time()
f()
print ‘%s %ss’%(name, time.time()-st)
times = 1000
arr = range(10000)
def tmap():
i = 0
while (i