闲来无事!!!测下编程语言谁跑的快,不作为标准评定,不喜勿喷
机器配置:8核i7 16G内存
测试1:n以内的整数累加,时间单位毫秒,每次测试10组
总结
- java 还是老大哥。在三个测试环境性能表现稳定
- go 是真特么快
- node 跑的比php python快
- php 和 python一个档次的
- 负载量级上升,php python成性能下降特别大。java>go=node
1.go实现
package main import ( "fmt" "time" "math" ) func main() { var start int64=time.Now().UnixNano() fmt.Println(start) var a int=1 //var total int=1000000 //100w //var total int=10000000 //1000w var total int=100000000 //1亿 for i := 1; i < total; i++{ a=a+i } var end int64=time.Now().UnixNano() fmt.Println(end) fmt.Println(float64(end - start) / math.Pow(10, 9)) }
2.python实现
import time #total=1000000 #100w #total=10000000 #1000w total=100000000 #1亿 start=time.time() sum=0 for i in range(1,total): sum=sum+i end=time.time() print(end-start)
3.node实现
var total=1000000 //100w //var total=10000000 //1000w //var total=100000000 //1亿 console.time('test'); sum=0 for(var i=1;i<total;i++){ sum+=sum+i } console.timeEnd('test');
4.php实现
<?php function microtime_float() { list($usec, $sec) = explode(" ", microtime()); return ((float)$usec + (float)$sec); } #$total=1000000; #$total=10000000; $total=100000000; $t1=microtime_float(); $sum=0; for($i=1;$i<$total;$i++){ $sum+=$i; } echo (microtime_float()-$t1);
5. java实现
import java.util.Date; public class demo { public static void main(String []args) { int x=1; //int total = 1000000; long startTime = System.currentTimeMillis(); //int total = 10000000; int total = 100000000; int sum=0; while( x < total ) { sum=sum+x; x++; } long endTime = System.currentTimeMillis(); System.out.println((endTime - startTime) + "ms"); } }