Last active
August 29, 2015 14:24
-
-
Save carsongee/d6a34da47346d082f158 to your computer and use it in GitHub Desktop.
Revisions
-
carsongee renamed this gist
Jul 14, 2015 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
carsongee created this gist
Jul 14, 2015 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,20 @@ def x_in_loop(): x = range(500) for i in x: if x == 253: return True return False def x_in_range(): x = range(500) return 253 in x if __name__=='__main__': from timeit import Timer timer = Timer("x_in_range()", "from __main__ import x_in_range") print("Timeit for `in`") print(timer.timeit()) timer = Timer("x_in_loop()", "from __main__ import x_in_loop") print("Timeit for `for` loop") print(timer.timeit())