Created
October 14, 2012 15:44
-
-
Save kitsunde/3888968 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cProfile | |
def conditions_test(a): | |
if a == 1 or a == 2 or a == 3 or a == 4: | |
return | |
return | |
def in_test(a): | |
if a in (1, 2, 3, 4): | |
return | |
return | |
def test_multiple_conditions(): | |
for i in range(10000000): | |
conditions_test(i % 4) | |
def test_in(): | |
for i in range(10000000): | |
in_test(i % 4) | |
cProfile.run('test_multiple_conditions()') | |
cProfile.run('test_in()') | |
$ python conditions.py | |
10000004 function calls in 4.219 seconds | |
Ordered by: standard name | |
ncalls tottime percall cumtime percall filename:lineno(function) | |
1 0.000 0.000 4.219 4.219 <string>:1(<module>) | |
1 2.406 2.406 4.219 4.219 conditions.py:14(test_multiple_conditions) | |
10000000 1.623 0.000 1.623 0.000 conditions.py:4(conditions_test) | |
1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects} | |
1 0.190 0.190 0.190 0.190 {range} | |
10000004 function calls in 3.820 seconds | |
Ordered by: standard name | |
ncalls tottime percall cumtime percall filename:lineno(function) | |
1 0.000 0.000 3.820 3.820 <string>:1(<module>) | |
1 2.232 2.232 3.820 3.820 conditions.py:19(test_in) | |
10000000 1.497 0.000 1.497 0.000 conditions.py:9(in_test) | |
1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects} | |
1 0.091 0.091 0.091 0.091 {range} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment