Preface
I personally still use PHP5.6, and 7.3 is purely for testing, because PHP7 already supports strong typing and no longer supports calling based on strings. function method, so the PHP version of my personal project is stuck at 5.6.
Recently I want to give it a try. How about the speed of PHP 5.6, 7.3 and Tomcat 7, 8, 9? I have read some articles before saying that PHP operates the database faster, while Java handles business. Logic is faster, so I want to hand over the business logic to Java, and hand over the database operations to PHP.
But is it faster this way? Compare it, the data speaks for itself!
By the way, I use the Pagoda panel for server management, and all service software installations are performed in the Pagoda panel.
Test Preface
During the test, I found that the results of Tomcat7 and 8.5 were similar. It is estimated that 9 also has the same result, so I will not test Tomcat9. The Tomcat part only tests 7 and 8.5 in business logic processing, and the rest only tests 8.5
Server configuration
● System: CentOS Linux 7.6.1810 (Core)
● Pagoda version: 6.9.8
● Manufacturer: Baidu Smart Cloud
● Type: Intensive computing ic3
● CPU: 1 core
● Memory: 1GB
Speed comparison
Business logic processing speed
Add from 0 to 10000000
PHP5.6
<?php $time_start = microtime(true); $count = 0; for ($i = 0; $i < 10000000; ++ $i) { $count += $i; } $time_end = microtime(true); echo ($time_end - $time_start); // 结果:0.34648394584656
Result: 0.34648394584656
PHP7.3
<?php $time_start = microtime(true); $count = 0; for ($i = 0; $i < 10000000; ++ $i) { $count += $i; } $time_end = microtime(true); echo ($time_end - $time_start); // 结果:0.12653613090515
Result: 0.12653613090515
Conclusion: PHP7.3 is three times faster than 5.6 in business logic processing
Tomcat7
<% java.util.Date d1 = new java.util.Date(); long start_time = d1.getTime(); // 单位:毫秒 long count = 0; for (long i = 0; i <= 10000000; ++ i) { count += i; } java.util.Date d2 = new java.util.Date(); long end_time = d2.getTime(); // 单位:毫秒 out.println(end_time - start_time); // 结果:17毫秒 %>
Result: 17 milliseconds, After a few more refreshes, it becomes 4~5 milliseconds, mainly 4 milliseconds
Tomcat8.5
Result: 99 milliseconds, even after a few more refreshes 4 milliseconds
Business logic test summary
After all, Java is a semi-compiled and semi-interpreted language, so it is normal to be fast. PHP7 reaches more than 100 milliseconds, but PHP5 is a bit slower at only 300 Multi-millisecond
Database IO test
Use PDO prepare and execute to test
PHP5.6
● INSERT inserts 10000 Rows: 37.575320005417 seconds
● SELECT reads 10,000 rows: 0.010236978530884 seconds
● SELECT loop reads 10,000 rows: 1.0460438728333 seconds
● UPDATE updates 10,000 rows: 0.04496788978 5767 seconds
● UPDATE loop to update 10,000 rows: 36.463224887848 seconds
● DELETE to delete 10,000 rows: 0.034432888031006 seconds
● DELETE loop to delete 10,000 rows: 37.198384046555 seconds
PHP7.3
● INSERT inserts 10,000 rows: 33.949599027634 seconds
● SELECT reads 10,000 rows: 0.021260023117065 seconds
● SELECT loop reads 10,000 rows : 1.0032389163971 seconds
● UPDATE updates 10,000 rows: 0.040410995483398 seconds
● UPDATE loop updates 10,000 rows: 36.759881019592 seconds
● DELETE deletes 10,000 rows: 0.046122074127 197 seconds
● DELETE loop to delete 10,000 rows: 35.682950973511 seconds
PHP summary: There is almost no version difference in database IO, and executing a single statement is faster than executing a statement in a loop
Tomcat8.5
The first execution before compilation, the second execution after compilation
● INSERT inserts 10000 rows: before compilation: 39.738 seconds, compilation After: 37.104 seconds
● SELECT reads 10,000 lines: before compilation: 0.079 seconds, after compilation: 0.028 seconds
● SELECT loop reads 10,000 lines: before compilation: 2.303 seconds, after compilation : 1.775 seconds
● UPDATE updates 10,000 rows: before compilation: 0.060 seconds, after compilation: 0.040 seconds
● UPDATE updates 10,000 rows in a loop: before compilation: 43.326 seconds, after compilation: 40.847 seconds
● DELETE deletes 10,000 rows: first execution: 0.137 seconds
● DELETE loop deletes 10,000 rows: first execution: 40.597 seconds
Summary: Java has strong business logic capabilities, but the database IO speed is slower than PHP, and the opposite is true for PHP.
Hybrid Development Test
Business logic is written in Java, PHP calls Java through CURL, test speed
Result:
First test: 0.51814317703247 seconds
Second test: 0.016547918319702 seconds
Summary:
The first test may take time because the Java side needs to be compiled, but the second test no longer needs to be compiled, so it is very fast.
After several more tests, the results were satisfactory, and the speed was about 10 times faster than PHP7.
It’s just that the disadvantage of mixed development is that the development efficiency is not high and may cause more pitfalls, but in terms of operation, each can have its own advantages.
I personally have a neutral attitude towards this, and do not recommend or oppose it, because there may be related needs in various projects, and this method may be the best choice.
The above is the detailed content of Speed comparison of PHP5.6 and 7.3, Tomcat7 and 8.5. For more information, please follow other related articles on the PHP Chinese website!