>>> x = [] >>> y = [] >>> >>> def test_loop(): ... for _ in range(5000000): ... x.append(_) ... >>> def test_map(): ... map(y.append, range(5000000)) ... >>> >>> import cProfile >>> >>> cProfile.run('test_loop()') 5000004 function calls in 0.842 seconds Ordered by: standard name ncalls tottime percall cumtime percall filename:lineno(function) 1 0.595 0.595 0.842 0.842 :1(test_loop) 1 0.000 0.000 0.842 0.842 :1() 5000000 0.189 0.000 0.189 0.000 {method 'append' of 'list' objects} 1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects} 1 0.058 0.058 0.058 0.058 {range} >>> cProfile.run('test_map()') 5 function calls in 0.282 seconds>>> Ordered by: standard name ncalls tottime percall cumtime percall filename:lineno(function) 1 0.032 0.032 0.282 0.282 :1(test_map) 1 0.000 0.000 0.282 0.282 :1() 1 0.193 0.193 0.193 0.193 {map} 1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects} 1 0.058 0.058 0.058 0.058 {range}