# On macOS Catalina, Python 3.12, Intel i9, Terminal, Apple MacBook Pro. # The main development machine, whose results are posted in the book. # timer ~/.../LP6E/Chapter21$ python3 timer_tests.py Python 3.12.2 on darwin forLoop : 0.26172 => [0…9999] listComp : 0.21396 => [0…9999] mapCall : 0.14579 => [0…9999] genExpr : 0.40869 => [0…9999] genFunc : 0.41037 => [0…9999] All results same. ~/.../LP6E/Chapter21$ python3 timer_tests2.py Python 3.12.2 on darwin forLoop : 0.28731 => [10…10009] listComp : 0.24670 => [10…10009] mapCall : 0.49116 => [10…10009] genExpr : 0.44572 => [10…10009] genFunc : 0.45115 => [10…10009] All results same. ~/.../LP6E/Chapter21$ python3 timer_tests3.py Python 3.12.2 on darwin forLoop : 0.36293 => [0…9999] listComp : 0.31024 => [0…9999] mapCall : 0.36537 => [0…9999] genExpr : 0.51059 => [0…9999] genFunc : 0.51390 => [0…9999] All results same. # pybench ~/.../LP6E/Chapter21$ python3 pybench_tests.py Python 3.12.2 on darwin at Jul-01-2024, 09:22:28 0.0531 '[x ** 2 for x in range(1000)]' 0.0611 'res=[]\nfor x in range(1000): res.append(x ** 2)' 0.0789 'list(map(lambda x: x ** 2, range(1000)))' 0.0737 'list(x ** 2 for x in range(1000))' 0.3984 "s = 'hack' * 2500\nx = [s[i] for i in range(10_000)]" 0.7814 "s = '?'\nfor i in range(10_000): s += '?'" ~/.../LP6E/Chapter21$ python3 pybench_tests2.py Python 3.12.2 on darwin at Jul-01-2024, 09:22:55 0.0734 '{x ** 2 for x in range(1000)}' 0.0935 'set(x ** 2 for x in range(1000))' 0.0819 's=set()\nfor x in range(1000): s.add(x ** 2)' 0.0739 '{x: x ** 2 for x in range(1000)}' 0.1161 'dict((x, x ** 2) for x in range(1000))' 0.0747 'd={}\nfor x in range(1000): d[x] = x ** 2' ~/.../LP6E/Chapter21$ python3 pybench_tests3.py Python 3.12.2 on darwin at Jul-01-2024, 09:23:29 0.2834 "res=[]\nfor x in 'hack' * 2500: res.append(ord(x))" 0.2184 "[ord(x) for x in 'hack' * 2500]" 0.1421 "list(map(ord, 'hack' * 2500))" 0.4079 "list(ord(x) for x in 'hack' * 2500)"