Skip to content

Instantly share code, notes, and snippets.

@kitsunde
Created October 14, 2012 15:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kitsunde/3888968 to your computer and use it in GitHub Desktop.
Save kitsunde/3888968 to your computer and use it in GitHub Desktop.
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