Comparison of the speed difference between PHP and Perl operating Memcached_PHP tutorial

WBOY
Release: 2016-07-13 17:35:13
Original
1069 people have browsed it

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");
$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

#!/usr/bin/perl
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

[root@lenovo5 ~]# time ./ test1k.pl

real 1m2.814s
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

2. Perl extensions are implemented differently from PHP extensions. PHP’s memcache client is PECL, which is a C extension, and perl’s extension implementation is likely to be perl. So there will be performance differences.

http://www.bkjia.com/PHPjc/508338.html

www.bkjia.com

truehttp: //www.bkjia.com/PHPjc/508338.htmlTechArticleDue to the recent work on memcached, I used php and perl to operate memcached in the performance test and found that php The performance difference between perl and memcached operations is about 40~50%...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!