php 运算代码
<?php
$startTime = microtime(true);
$sum = 0;
for($i = 1; $i <= 100000000; $i++){
$sum++;
}
$endTime = microtime(true);
echo $sum;
$runtime = ($endTime - $startTime) * 1000; //将时间转换为毫秒
echo "运行时间: {$runtime} 毫秒";
golang 运行代码
package main
import (
"fmt"
"time"
)
func test() {
start := time.Now()
sum := 0
for i := 0 ; i < 100000000 ; i++ {
sum ++
}
elapsed := time.Since(start)
fmt.Println(sum)
fmt.Println("耗时:", elapsed)
}
func main() {
test()
}
重复三次取平均值:
php5.6 :9780.9720039368 毫秒
php7.2 :1030.2329063416 毫秒
golang :54.449365ms
来源:oschina
链接:https://my.oschina.net/stupidboyblog/blog/3196141