Created
May 8, 2014 08:51
-
-
Save anonymous/6a895ca27c0ca98aa0df to your computer and use it in GitHub Desktop.
simple benchmark
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
""" | |
>>> time python2.7 ./filename.py > /dev/null | |
real 0m17.911s | |
user 0m17.059s | |
sys 0m0.834s | |
>>> time pypy ./filename.py > /dev/null # pypy2.2.1 gevent 1.1.0-dev | |
real 0m14.118s | |
user 0m9.993s | |
sys 0m0.787s | |
""" | |
from gevent.pool import Pool | |
SIZE = 655350 | |
pool = Pool(SIZE) | |
def incr(n): | |
print n+1 | |
for i in xrange(SIZE): | |
pool.wait_available() | |
pool.spawn(incr, i) | |
pool.join() |
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
package main | |
/* | |
>>> go build filename.go | |
>>> time GOMAXPROCS=1 ./filename > /dev/null | |
real 0m1.083s | |
user 0m0.834s | |
sys 0m0.255s | |
*/ | |
import ( | |
"fmt" | |
"sync" | |
) | |
const ( | |
SIZE = 655350 | |
) | |
func incr(num int) { | |
fmt.Println(num+1) | |
} | |
func main(){ | |
var wg sync.WaitGroup | |
defer wg.Wait() | |
wg.Add(SIZE) | |
for i:=0; i<SIZE; i++ { | |
go func(num int){ | |
defer wg.Done() | |
incr(num) | |
}(i) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment