golang与python多线程的并发速度

时间:2023-12-20 20:15:20

一.golang的代码

package main

import (
"fmt"
"time"
) func Text_goroute(a int, b int) {
sum := a + b
fmt.Println(sum)
} func main() {
start:=time.Now()
for i:=0;i<1000;i++{
go Text_goroute(i,i+1)
}
end:=time.Since(start)
fmt.Println(end)
}

二.python的代码

import threading,time

def text(a, b):
c = a + b
print(c) start=time.time() for i in range(1000):
t=threading.Thread(target=text,args=(i,i+1))
t.start() end=time.time()
print(end-start)

三.最后的运算速度比较

golang的是2.9906ms

python的0.15055203437805176s,换算成ms是150.5520344ms

结果是golang比python快了近50倍