Skip to content

Instantly share code, notes, and snippets.

@avalanchy
Created September 18, 2013 12:54
Show Gist options
  • Save avalanchy/6608760 to your computer and use it in GitHub Desktop.
Save avalanchy/6608760 to your computer and use it in GitHub Desktop.
Best way to stop forever loop on event - Python
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