Home >Backend Development >PHP Tutorial >Comparison of the speed difference between PHP and Perl operating Memcached_PHP tutorial
Due to the recent work on memcached In the performance test, php and perl were used to operate memcached. The results found that the performance difference between php and perl for memcached operation was about 40~50% The following is a test script, the operation is the same. Use 1k data to repeat 512,000 times. A total of 500M of memcached data is inserted php operation script ini_set("memcache.hash_function","crc32"); #!/usr/bin/perl real 1m2.814s
$memcache=newMemcache;
$memcache->addServer(localhost,30001);
$ memcache->flush();
for($i=0;$i<512000;$i++){
$memcache->set($i,
"Total 1k fill data" ,0,1000);
}
?>
Followed by the perl script
use Cache::Memcached();
$memcache=newCache::Memcached{servers=>["localhost:30001"]};
$ memcache->flush_all();
for($i=0;$i<512000;$i++){
$memcache->set($i,
"Total 1k fill data" ; Use time to time the execution
The results of 3 executions are as follows
[root@lenovo5 ~]# time ./test1k.pl
real 1m2.265s
user 0m36.427s
sys 0m17.114s
user 0m36.380s
sys 0m17.463s
[root@lenovo5 ~]# time ./test1k.pl
real 1m13.684s
user 0m44.603s
sys 0m18.366s
[root@lenovo5 ~]# time php ./test1k.php
real 0m38.055s
user 0m11.768s
sys 0m13.89 1s
[root@lenovo5 ~]# time php ./test1k.php
real 0m38.892s
user 0m12.416s
sys 0m14.044s
[root@lenovo5 ~]# time php . /test1k.php
real 0m38.955s
user 0m12.430s
sys 0m13.088s
The difference is obvious. Perl takes about 1 minute to execute while php only takes less than 40 seconds, which is php Execution is about 40% faster than perl
After analysis, there are several possible factors
1. Perl’s string processing speed is slow. We see that the perl version of set does not need to add a length parameter. In this case, each insertion may require the set function to determine the length of the incoming string. This may be slower. .But then we found that although PHP's set has a length parameter, this parameter is not mandatory. For example, if I write 1000 as the parameter, the actual string is 1200. The result will be a string of 1200 length inserted without truncation. .So this point is not very tenable