python与goland多线程对比 - Go语言中文社区

python与goland多线程对比


python:

# -*- coding: utf-8 -*-

# @Time    : 2020-01-02 10:52

# @Author  : xiaobin

# @File    : thread_test.py

# @Software : PyCharm

import threading

import datetime

"""

对比 golang 多线程性能差异

"""

def text(a, b):

c = a + b

return c

start = datetime.datetime.now()

for iin range(10000):

t = threading.Thread(target=text, args=(i, i+1))

t.start()

end = datetime.datetime.now()

print end - start


goland:

package main

import (

"fmt"

"time"

)

func Text_goroute(aint, bint)int {

sum := a + b

return sum

}

func main() {

start:=time.Now()

for i:=0;i<10000;i++{

go Text_goroute(i,i+1)

}

end:=time.Since(start)

fmt.Println(end)

}

执行结果:

python : 0:00:00.797247

goland: 4.951978ms

结论:差不多160倍的差距

备注:不同主机上面差异可能会不同,但是goland多线程性能高IO优势数十倍于python是成立的。

衍生:python threading 与python gevent 与goland 并发压测HTTP接口差异;其实重点关注是python gevent 与goland谁更优且区别,python threading应该是最差的。

版权声明:本文来源简书,感谢博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://www.jianshu.com/p/822e389f3930
站方申明:本站部分内容来自社区用户分享,若涉及侵权,请联系站方删除。
  • 发表于 2020-01-12 11:42:23
  • 阅读 ( 1976 )
  • 分类:Goland

0 条评论

请先 登录 后评论

官方社群

GO教程

猜你喜欢