2004年03月09日(火) [過去の今日]
#1 PHP vs Perl
なんとなくベンチマークを取ってみたり。
#!/usr/bin/perl $time = time(); print "Content-type: text/html\n\n"; print "$time<br>"; for ( $i = 0; $i <= 1000000; $i++) { print "$i"; } $time = time(); print "<br>$time<br>";
<?php $time = time(); print "$time<br>"; for ( $i = 0; $i <= 1000000; $i++) { print "$i"; } $time = time(); print "<br>$time<br>"; ?>
こんなソースでローカルからmozillaで取得してみる。すると、Perlは110秒、PHPは114秒かかっていた。シチュエーションにもよるのだろうが、PerlでCGIを書いた方が微妙に速いということだろうか。
(@822)
@ バージョン:
バージョンを書き忘れてた。両方ともdebian(sid)のパッケージであり、最適化コンパイルなどはしていない。
$ dpkg -l | grep php ii php-elisp 1.0.5-1fix1 Emacs support for php files ii php4 4.3.3-5 A server-side, HTML-embedded scripting langu ii php4-cgi 4.3.3-5 A server-side, HTML-embedded scripting langu ii php4-mysql 4.3.4-2 MySQL module for php4 ii php4-pear 4.3.4-2 PEAR - PHP Extension and Application Reposit $ dpkg -l | grep '^ii perl' ii perl 5.8.3-2 Larry Wall's Practical Extraction and Report ii perl-5.6 6.3 Transitional package. ii perl-5.6-base 6.3 Transitional package. ii perl-5.6-debug 6.3 Transitional package. ii perl-5.6-doc 6.3 Transitional package. ii perl-5.6-suid 6.3 Transitional package. ii perl-base 5.8.3-2 The Pathologically Eclectic Rubbish Lister. ii perl-debug 5.8.3-2 Debug-enabled Perl interpreter. ii perl-doc 5.8.3-2 Perl documentation. ii perl-modules 5.8.3-2 Core Perl modules. ii perl-suid 5.8.3-2 Runs setuid Perl scripts. ii perl-tk 800.024-1.2 Perl module providing the Tk graphics librar ii perlmagick 5.5.7.9-1.1 A perl interface to the libMagick graphics r
(@826)
@ 他の手法:
PHPってapacheのモジュールで動くから、mod_perlみたいに高速化されてるのかなと思っただけに意外。誤差の範囲としてもたいした差が無いのだなあ。
と思ってたら、 ベンチマークページ を見付けた。これを見るとPHPのほうが圧倒的に速いな。なるほど、abコマンドってのがあるのか。こりゃいいな。mozillaより楽そうだ。
Benchmarking localhost (be patient).....done Server Software: Apache/1.3.29 Server Hostname: localhost Server Port: 80 Document Path: /tmp/bench.pl Document Length: 5888929 bytes Concurrency Level: 1 Time taken for tests: 1.016 seconds Complete requests: 1 Failed requests: 0 Broken pipe errors: 0 Total transferred: 5889105 bytes[- 日記システム警告:コマンド PRE の中にコマンド HTML を含めることはできません。コマンド /PRE が抜けている可能性があります。-]
Requests per second: 0.98 [#/sec] (mean)
Time per request: 1016.00 [ms] (mean)
Time per request: 1016.00 [ms] (mean, across all concurrent requests)
Transfer rate: 5796.36 [Kbytes/sec] received
Benchmarking localhost (be patient).....done Server Software: Apache/1.3.29 Server Hostname: localhost Server Port: 80 Document Path: /tmp/bench.php Document Length: 5888929 bytes Concurrency Level: 1 Time taken for tests: 4.888 seconds Complete requests: 1 Failed requests: 0 Broken pipe errors: 0 Total transferred: 5889130 bytes[- 日記システム警告:コマンド PRE の中にコマンド HTML を含めることはできません。コマンド /PRE が抜けている可能性があります。-]
Requests per second: 0.20 [#/sec] (mean)
Time per request: 4888.00 [ms] (mean)
Time per request: 4888.00 [ms] (mean, across all concurrent requests)
Transfer rate: 1204.81 [Kbytes/sec] received
ぬう? 今度は圧倒的にperlのが速いぞ。どういうこっちゃ。単純ループならapache moduleのメリットは無いっつーことかのう。
(@829)