简单比较一下php7和java8的计算和字符串操作性能。
机器:osx 10.10 intel corei5 4GB
php7.php:
for($i=0; $i<10000000; $i++){
echo 'php time:' . ($t2 - $t1)*1000 . "msn";
$s = "abcdefkkbghisdfdfdsfds";
$c = $a * $b + $a / $b - pow($a, 2);
$d = substr($s, 0, strpos($s, 'kkb')) . strval($c);
java8.java:
public static void main(String[] args)
long t1 = System.currentTimeMillis();
for(int i=0; i<10000000; i++){
long t2 = System.currentTimeMillis();
System.out.println("java time:" + String.valueOf(t2 - t1) + "ms");
static void aaa(float i){
String s = "abcdefkkbghisdfdfdsfds";
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++){
var t2 = (new Date()).getTime();
console.log("nodejs time:" + (t2 - t1) + "ms");
var s = "abcdefkkbghisdfdfdsfds";
var c = a * b + a / b - Math.pow(a, 2);
var d = s.substring(0, s.indexOf("kkb")) + c.toString();
lua5.2.lua
s = "abcdefkkbghisdfdfdsfds"
c = a * b + a / b - math.pow(a, 2)
d = string.sub(s, 0, string.find(s, "kkb")) .. tostring(c)
print("lua time:" .. (t2 - t1) * 1000 .. "ms")
分别执行1000万次计算,依次执行以下命令:
java -jar java8jar
node node5.js
php php7.php
luajit lua5.2.lua
lua lua5.2.lua
结果:

结论:由此可见就计算性能来说,java8 > nodejs5 > php7 > luajit > lua
java8是php7的5.2倍,nodejs5是php7的1.8倍,php7和luajit相当。
说lua是最快的脚本,那是往事了。静态语言的计算性能肯定比动态语言强很多。
对于密集计算,java是最好的选择;考虑到web的性能的瓶颈往往在数据库和IO,nodejs和php都是很好的选择。我个人喜欢php,无论从开发和部署,都比nodejs顺心点。