This article will introduce to you the performance differences between php7, java8, nodejs5 and lua5.2. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to everyone.
Let’s briefly compare the calculation and string operation performance of php7 and java8.
Machine: osx 10.10 intel corei5 4GB
php7.php:
<?php $t1 = microtime(true); for($i=0; $i<10000000; $i++){ aaa($i); } $t2 = microtime(true); echo 'php time:' . ($t2 - $t1)*1000 . "ms\n"; function aaa($i){ $a = $i + 1; $b = 2.3; $s = "abcdefkkbghisdfdfdsfds"; if($a > $b){ ++$a; }else{ $b = $b + 1; } if($a == $b){ $b = $b + 1; } $c = $a * $b + $a / $b - pow($a, 2); $d = substr($s, 0, strpos($s, 'kkb')) . strval($c); } ?>
java8.java:
public class Main { public static void main(String[] args) { long t1 = System.currentTimeMillis(); for(int i=0; i<10000000; i++){ aaa((float)i); } long t2 = System.currentTimeMillis(); System.out.println("java time:" + String.valueOf(t2 - t1) + "ms"); } static void aaa(float i){ float a = i + 1; float b = 2.3f; String s = "abcdefkkbghisdfdfdsfds"; if(a > b){ ++a; }else{ b = b + 1; } if(a == b){ b = b + 1; } float c = (float) (a * b + a / b - Math.pow(a, 2)); String d = s.substring(0, s.indexOf("kkb")) + String.valueOf(c); } }
node5.js:
var t1 = (new Date()).getTime(); for(var i=0; i<10000000; i++){ aaa(i); } var t2 = (new Date()).getTime(); console.log("nodejs time:" + (t2 - t1) + "ms"); function aaa(i){ var a = i + 1; var b = 2.3; var s = "abcdefkkbghisdfdfdsfds"; if(a > b){ ++a; }else{ b = b + 1; } if(a == b){ b = b + 1; } var c = a * b + a / b - Math.pow(a, 2); var d = s.substring(0, s.indexOf("kkb")) + c.toString(); }
lua5.2.lua
function aaa(i) a = i + 1 b = 2.3 s = "abcdefkkbghisdfdfdsfds" if(a > b) then a = a+1 else b = b + 1 end if(a == b) then b = b + 1 end c = a * b + a / b - math.pow(a, 2) d = string.sub(s, 0, string.find(s, "kkb")) .. tostring(c) end t1 = os.clock() for i=0, 10000000, 1 do aaa(i) end t2 = os.clock() print("lua time:" .. (t2 - t1) * 1000 .. "ms")
Execute 10 million calculations respectively, and execute the following commands in sequence:
java -jar java8jar
node node5.js
php php7.php
luajit lua5.2.lua
lua lua5.2.lua
Result:
Conclusion: It can be seen that in terms of computing performance, java8 > nodejs5 > php7 > luajit > lua
java8 is 5.2 times that of php7, nodejs5 is 1.8 times that of php7, php7 and luajit quite.
It is a thing of the past to say that Lua is the fastest script. The computing performance of static languages is definitely much better than dynamic languages.
For intensive computing, java is the best choice; considering that the bottleneck of web performance is often in the database and IO, nodejs and php are both good choices. I personally like PHP, which is more convenient than nodejs in terms of development and deployment.
Special note: If there is no parameter i in function aaa(i), then nodejs is the fastest and is completed in 1000ms. It is estimated that nodejs caches the same execution results. Many people have made this mistake. After testing, they think nodejs is much faster than java.
Recommended learning: php video tutorial
The above is the detailed content of What is the difference in performance between php7, java8, nodejs5 and lua5.2. For more information, please follow other related articles on the PHP Chinese website!