我编写了两个程序,使用Riemann和计算具有一定数量矩形的函数区域,一个用Go编写,另一个用C++编写.
目标是测量执行时间并查看多线程中哪种语言更快.
我使用bash脚本4在32核服务器(双Intel Xeon)上运行该程序,以使用1,2,4,8,16和32个线程运行它.该脚本用于time --format %U获取执行时间.
但正如您在运行结果中看到的那样,使用1核心的Go版本是1.19秒,而使用32核心则是1.69秒!我认为使用更多核心会使计算速度更快......
我编写程序时出错了吗?时间的衡量标准是准确的吗?或者结果可能不错但是怎么样?
提前感谢您的回答!
资料来源:
转码:https://github.com/Mistermatt007/Benchmark-go-vs-cpp/blob/master/CalculGo/Calcul.go
C++代码:https://github.com/Mistermatt007/Benchmark-go-vs-cpp/blob/master/CalculCpp/Calcul.cpp
启动脚本:https://github.com/Mistermatt007/Benchmark-go-vs-cpp/blob/master/script/Launch.sh
黎曼总结:http://mathworld.wolfram.com/RiemannSum.html
第一个结果:https://github.com/Mistermatt007/Benchmark-go-vs-cpp/blob/master/results/GoVSCpp.txt