Created
February 19, 2011 00:15
-
-
Save teepark/834658 to your computer and use it in GitHub Desktop.
coroutine scheduler microbenchmarks
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 characters
# corotest.io: | |
Base := Object clone do( | |
go := method( | |
counter atPut(0, counter at(0) + 1) | |
) | |
counter := list(0) | |
) | |
schedule := Date secondsToRun( | |
for (i, 1, 10000, | |
Base clone asyncSend(go) | |
) | |
) | |
switch := Date secondsToRun(yield) | |
"counter: #{Base counter at(0)}, schedule time: #{schedule}, switch time: #{switch}" interpolate println | |
# corotest.py: | |
import time | |
from greenhouse import schedule, pause | |
counter = [0] | |
def go(): | |
counter[0] += 1 | |
start = time.time() | |
for i in xrange(10000): | |
schedule(go) | |
schedule_time = time.time() - start | |
start = time.time() | |
pause() | |
switch_time = time.time() - start | |
print "counter: %d, schedule time: %s, switch time: %s" % (counter[0], schedule_time, switch_time) | |
$ python corotest.py | |
counter: 10000, schedule time: 0.0155069828033, switch time: 0.0182120800018 | |
$ io corotest.io | |
counter: 10000, schedule time: 1.6654710000000001, switch time: 12.9423689999999993 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment