Skip to content

Instantly share code, notes, and snippets.

@snower
Last active January 22, 2016 06:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save snower/27d8fc414f073141376e to your computer and use it in GitHub Desktop.
Save snower/27d8fc414f073141376e to your computer and use it in GitHub Desktop.
greenlet性能测试
# -*- coding: utf-8 -*-
# 15/1/16
# create by: snower
import time
import greenlet
import threading
m = greenlet.getcurrent()
def test():
pass
def testg():
m.switch()
t = time.time()
for i in range(10000):
test()
print time.time() - t
t = time.time()
for i in range(10000):
g = greenlet.greenlet(test)
g.switch()
print time.time() - t
g = greenlet.greenlet(testg)
t = time.time()
for i in range(10000):
g.switch()
print time.time() - t
t = time.time()
for i in range(10000):
th=threading.Thread(target=test)
th.start()
th.join()
print time.time() - t
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment