Created
January 9, 2013 22:17
-
-
Save saghul/4497505 to your computer and use it in GitHub Desktop.
pyuv loop.stop() vs custom loop
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 pyuv | |
N = 1000000 | |
def idle_cb(handle): | |
handle.count += 1 | |
if handle.count == N: | |
handle.loop.stop() | |
loop = pyuv.Loop() | |
idle = pyuv.Idle(loop) | |
idle.count = 0 | |
idle.start(idle_cb) | |
loop.run() | |
print idle.count |
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
(master)(pyuv27)saghul@hal:~/src/pyuv | |
$ time python i1.py | |
1000000 | |
real 0m2.408s | |
user 0m1.638s | |
sys 0m0.611s | |
(master)(pyuv27)saghul@hal:~/src/pyuv | |
$ time python i1.py | |
1000000 | |
real 0m2.342s | |
user 0m1.641s | |
sys 0m0.618s | |
(master)(pyuv27)saghul@hal:~/src/pyuv | |
$ time python i1.py | |
1000000 | |
real 0m2.384s | |
user 0m1.623s | |
sys 0m0.610s | |
(master)(pyuv27)saghul@hal:~/src/pyuv | |
$ |
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 pyuv | |
N = 1000000 | |
stop = False | |
def idle_cb(handle): | |
handle.count += 1 | |
if handle.count == N: | |
global stop | |
stop = True | |
loop = pyuv.Loop() | |
idle = pyuv.Idle(loop) | |
idle.count = 0 | |
idle.start(idle_cb) | |
while not stop and loop.run(pyuv.UV_RUN_ONCE): | |
pass | |
print idle.count |
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
(master)(pyuv27)saghul@hal:~/src/pyuv | |
$ time python i2.py | |
1000000 | |
real 0m3.572s | |
user 0m2.703s | |
sys 0m0.720s | |
(master)(pyuv27)saghul@hal:~/src/pyuv | |
$ time python i2.py | |
1000000 | |
real 0m3.515s | |
user 0m2.713s | |
sys 0m0.720s | |
(master)(pyuv27)saghul@hal:~/src/pyuv | |
$ time python i2.py | |
1000000 | |
real 0m3.647s | |
user 0m2.714s | |
sys 0m0.724s | |
(master)(pyuv27)saghul@hal:~/src/pyuv | |
$ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment