Last active
December 25, 2015 11:09
-
-
Save mstrongdev/6967163 to your computer and use it in GitHub Desktop.
A quick performance test between the "while(True) and break" method of control flow logic and the "while(conditional)" method.
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 timeit | |
def while_var(): | |
count = 1000 | |
while(count > 0): | |
count -= 1 | |
def while_break(): | |
count = 1000 | |
while(1): | |
count -= 1 | |
if(count <= 0): | |
break | |
n = 100000 | |
print("While Loop with Conditional (n="+str(n)+"):") | |
print(timeit.timeit('while_var()', setup='from __main__ import while_var', number=n)) | |
print("While Loop with break statement (n=" + str(n) + "):") | |
print(timeit.timeit('while_break()', setup='from __main__ import while_break', number=n)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment