Created
September 18, 2013 12:54
-
-
Save avalanchy/6608760 to your computer and use it in GitHub Desktop.
Best way to stop forever loop on event - Python
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
In [1]: run = 1 | |
In [2]: event = 17 | |
In [3]: def a(): | |
...: if event == 17: | |
...: run = 0 | |
...: | |
In [4]: def b(): | |
...: run = event - 17 | |
...: | |
In [5]: def c(): | |
...: run = event ^ 17 | |
...: | |
In [6]: %timeit a() | |
10000000 loops, best of 3: 108 ns per loop | |
In [7]: %timeit b() | |
10000000 loops, best of 3: 88.4 ns per loop | |
In [8]: %timeit c() | |
10000000 loops, best of 3: 97 ns per loop |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment