基于什么样的理由 PHP 比其它 CGI
2024-05-04 22:56:22
供稿:网友
q:基于什么样的理由 php 比其它 cgi 好呢?有没有比较具体的数据可以证明 php 执行与其它 cgi 执行的效率好 ? 现在我的公司是用 c 来写 cgi 的,如果换成 php,会不会比较好呢 ?没有强而有力的依据的话,我就没办法说服上面的人让我转成 php 了...
a:
我认为"好" 要有三点
第一: 写出来的程式的执行速度快.
第二: 遇到有大量存取时的执行效能强.
第三: 程式开发的时间快,易维护。
php在这三点中,虽都不一定是最好的,但也都在前茅
以下是c,php和perl在速度方面的比较
我用下面的算式测试
$s=1.0;
for ($i=1;$i<=10;$i++) {
for ($j=1;$j<=10;$j++) {
$s=$s*1.0005;
$s=$s/1.0004;
};
};
print $s;
?>
然后用ab -n 10000 -c 20 http://mycgi
测试,结果
c语言用了 37.511 秒
php3用了 45.393 秒
perl用了 68.418 秒
看起是c 最快没错,不过,和php3的结果没有太大
的差距。
perl最慢
以下为测试数据
==============================================
c 语言
==============================================
document path: /~evan/test/gcc.cgi
document length: 19 bytes
concurrency level: 20
time taken for tests: 37.511 seconds
complete requests: 10000
failed requests: 0
total transferred: 1750000 bytes
html transferred: 190000 bytes
requests per second: 266.59
transfer rate: 46.65 kb/s received
connnection times (ms)
min avg max
connect: 0 30 3001
processing: 4 40 69
total: 4 70 3070
php3
==============================================
document path: /~evan/test/php3.php3
document length: 15 bytes
concurrency level: 20
time taken for tests: 45.393 seconds
complete requests: 10000
failed requests: 0
total transferred: 1710000 bytes
html transferred: 150000 bytes
requests per second: 220.30
transfer rate: 37.67 kb/s received
connnection times (ms)
min avg max
connect: 0 34 3039
processing: 6 53 183
total: 6 87 3222
perl
==============================================
document path: /~evan/test/perl.cgi
document length: 17 bytes
concurrency level: 20
time taken for tests: 68.418 seconds
complete requests: 10000
failed requests: 0
total transferred: 1730173 bytes
html transferred: 170017 bytes
requests per second: 146.16
transfer rate: 25.29 kb/s received
connnection times (ms)
min avg max
connect: 0 22 3005
processing: 9 112 323
total: 9 134 3328
菜鸟学堂: