Comparison of Memcached operation speed between PHP and Perl

Source: Internet
Author: User
Tags perl script
Comparison of Memcached operation speed between PHP and Perl; comparison of Memcached operation speed between PHP and Perl, recently, memcached was used in performance tests. php and perl were used to perform memcached operations. The results showed that the performance difference between php and perl on memcached operations was approximately 40 ~ The following is a test script between 50%.

Due to the recent work on memcached

In the performance test, php and perl were used to operate on memcached. The results showed that the performance difference between php and perl on memcached operations was about 40 ~ Between 50%

The following is a test script, which performs the same operation. 512000 Times of data repeat with 1 k. a total of MB 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 I <512000; $ I ++ ){
$ Memcache-> set ($ I,
"Fill data of 1 K in total );
}
?>
Next is the perl script.

#! /Usr/bin/perl
Use Cache: Memcached ();
$ Memcache = newCache: Memcached {'servers' => ["localhost: 30001"]};
$ Memcache-> flush_all ();
For ($ I = 0; I I <512000; $ I ++ ){
$ Memcache-> set ($ I,
"Fill data of 1 K in total ");
}
$ Memcache-> disconnect_all ();
The number of lines in the code is almost the same.
However, the test results are quite different.
In linux, we use time to timing the execution.
The result of the three executions is as follows:

[Root @ lenovo5 ~] # Time./test1k. pl
Real 1M2. 265 s
User 0m36. 427 s
Sys 0m17. 114 s
[Root @ lenovo5 ~] # Time./test1k. pl
Real 1M2. 814 s
User 0m36. 380 s
Sys 0m17. 463 s
[Root @ lenovo5 ~] # Time./test1k. pl
Real 1m13. 684 s
User 0m44. 603 s
Sys 0m18. 366 s
[Root @ lenovo5 ~] # Time php./test1k. php
Real 0m38. 055 s
User 0m11. 768 s
Sys 0m13. 891 s
[Root @ lenovo5 ~] # Time php./test1k. php
Real 0m38. 892 s
User 0m12. 416 s
Sys 0m14. 044 s
[Root @ lenovo5 ~] # Time php./test1k. php
Real 0m38. 955 s
User 0m12. 430 s
Sys 0m13. 088 s
The difference is obvious. It takes about 1 minute to execute perl, and less than 40 seconds to execute php, that is, the execution of php is about 40% faster than that of perl.

Possible factors after Analysis

1. the processing speed of perl strings is slow. we can see that the length parameter does not need to be added to the set of The perl version. in this way, the set function may be required to determine the length of the input string for each insertion. this may be slow. however, we later found that php's set has a length parameter. however, this parameter is not mandatory. for example, if my parameter is set to 1000, the actual string is 1200. the result is a string with a length of 1200 and is not truncated. so this is not very good.

2. extensions of perl are different from extensions of php. the memcache Client of php is PECL. that is, C extension, and the extension implementation of perl is probably perl. Therefore, there will be performance differences.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.