本篇内容主要讲解“C,GO,JAVA,NodeJs性能哪个更好”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“C,GO,JAVA,NodeJs性能哪个更好”吧!
C代码:
#include <stdio.h> #include <time.h> int main() { double m =0; time_t start_t,end_t; time(&start_t); for (double i=2; i<999999999;i++){ m += ( (i+1)/(i-1)*(i-(i/i-i)) )-( (i+1)/(i-1)*(i-(i/i-i)) -1); } time(&end_t); printf("%f %f",m,difftime(end_t,start_t)); return 0; } //执行行时间20ms
Go代码:
package main import ( "fmt" "time" ) // 性能测试 2ms func main(){ var m float64=0 t1:=time.Now().Unix() for i:=2; i<999999999;i++{ m += float64( (i+1)/(i-1)*(i-(i/i-i)) )-float64( (i+1)/(i-1)*(i-(i/i-i)) -1) } t2:=time.Now().Unix() fmt.Println(m,t2-t1) } //执行行时间27ms
java代码:
public static void main(String[] argus) { double m = 0; long t1 = new Date().getTime(); for (double i = 2; i < 999999999; i++) { m += ((i + 1) / (i - 1) * (i - (i / i - i))) - ((i + 1) / (i - 1) * (i - (i / i - i)) - 1); } long t2=new Date().getTime(); System.out.println(t2-t1); } //执行时间 10415ms
nodejs代码:
function main(){ "use strict"; var m =0 var t1= new Date().getTime(); for (let i=2; i<999999999;i++){ m += ( (i+1)/(i-1)*(i-(i/i-i)) )-(i+1)/(i-1)*(i-(i/i-i)) -1 } var t2 =new Date().getTime(); console.log(m,t2-t1) } main() //执行行时间11272ms
性能排名:
1) c/20ms
2) go/27ms
3 )java/10415ms
4 )nodejs/11272ms
到此,相信大家对“C,GO,JAVA,NodeJs性能哪个更好”有了更深的了解,不妨来实际操作一番吧!这里是亿速云网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!
原创文章,作者:306829225,如若转载,请注明出处:https://blog.ytso.com/220183.html