您的位置 首页 golang

golang与php的性能对比

闲来无事,测试下golang和php的性能如何。

方法:分别进行1百万,1千万,1亿次和10亿循环.

一千万次循环:

golang 用时 0.003232412s

php 用时 0.2235701084137s

PHP用时是golang的69.165倍

一亿次循环:

golang 用时 0.035078093s

php 用时 2.1999928951263s

PHP用时是golang的62.717倍

十亿次循环:

golang 用时 0.345632014s

php 用时 22.11152100563s

PHP用时是golang的63.974倍

代码如下:

golang代码:

package main

import (

“time”

“fmt”

)

func main() {

start :=time.Now()

s :=0

for i:=0; i<1000000000;i++ {

s+=i

}

fmt.Printf(“%.9fs elapsed\n”, time.Since(start).Seconds())

}

PHP代码:

<?php
$mtime=microtime(true);
$s=0;
for($i=0;$i<1000000000;$i++){
$s+=$i;
}
echo microtime(true) - $mtime; 

golang的性能真是厉害~,虽然如此,我还是想说:PHP是世界上最好的语言!哈哈

文章来源:智云一二三科技

文章标题:golang与php的性能对比

文章地址:https://www.zhihuclub.com/97987.shtml

关于作者: 智云科技

热门文章

网站地图