這里有一個性能測試網(wǎng)站
我對于網(wǎng)站測試的結(jié)果,我總結(jié)的情況就是兩點.
1. 排在后面的基本都是動態(tài)類型語言,靜態(tài)類型語言相對容易優(yōu)化到性能差不多的結(jié)果.
2. 同一個語言代碼寫得好差產(chǎn)生的性能差異,遠遠比各種語言最好的代碼性能差異大.
不過也有反例,我們之前那個程序就是.
//java版本
public static void main(String[] args) {
List<String> paramsList = new LinkedList<String>() {{
add(">= 3");
add("< 7");
}};
JavaRangeMatcher matcher = new JavaRangeMatcher(paramsList);
Random random = new Random();
long timeBegin = System.currentTimeMillis();
for (int i = 0; i < 100000000; i++) {
int input = random.nextInt() % 10;
matcher.check(input);
}
long timeEnd = System.currentTimeMillis();
System.out.println("java 消耗時間: " + (timeEnd - timeBegin) + " 毫秒");
//java 消耗時間: 3263 毫秒
}
//scala版本
def main(args: Array[String]) {
val requirements = Seq(">= 3", "< 7")
val rangeMatcher = RangeMatcher(requirements)
val timeBegin = System.currentTimeMillis()
0 until 100000000 foreach {
case _ =>
rangeMatcher.check(Random.nextInt(10))
}
val timeEnd = System.currentTimeMillis()
println(s"scala 消耗時間 ${timeEnd - timeBegin} 毫秒")
//scala 消耗時間 2617 毫秒
}
想想這是為什么?
更多建議: