We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
最近在接触python2.7版本中的gevent多线程,所以就想记录gevent多线程模型的性能和Golang goroutine性能之间的区别。
希望能达成的目标:
The text was updated successfully, but these errors were encountered:
使用gevent运行。
from gevent import monkey; monkey.patch_all() import gevent def f(i): sum = 0 for i in range(1000000000): x = i x += 1 x *= 2 x /= 3 x -= 5 sum += x print sum gevent.joinall([ gevent.spawn(f, 1), gevent.spawn(f, 2), gevent.spawn(f, 3), ])
# time python ./gevent_demo.py 333328333333 333328333333 333328333333 real 0m0.592s user 0m0.450s sys 0m0.040s
Sorry, something went wrong.
package main import ( "log" "sync" ) func f() { sum := 0 for i := 0; i < 1000000000; i++ { x := i x += 1 x *= 2 x /= 3 x -= 5 sum += x } log.Printf("sum=%d", sum) } func main() { wg := new(sync.WaitGroup) wg.Add(3) for i := 0; i < 3; i++ { go func() { f() wg.Done() }() } wg.Wait() }
运行
# go build ./goroutine_demo.go # time ./goroutine_demo 2020/10/27 16:36:32 sum=333333328333333333 2020/10/27 16:36:32 sum=333333328333333333 2020/10/27 16:36:32 sum=333333328333333333 real 0m1.036s user 0m3.082s sys 0m0.008s
No branches or pull requests
最近在接触python2.7版本中的gevent多线程,所以就想记录gevent多线程模型的性能和Golang goroutine性能之间的区别。
希望能达成的目标:
The text was updated successfully, but these errors were encountered: