企业🤖AI Agent构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
这里有一个[性能测试](http://benchmarksgame.alioth.debian.org/u64/performance.php?test=binarytrees&sort=elapsed)网站 我对于网站测试的结果,我总结的情况就是两点. 1\. 排在后面的基本都是动态类型语言,静态类型语言相对容易优化到性能差不多的结果. 2\. 同一个语言代码写得好差产生的性能差异,远远比各种语言最好的代码性能差异大. ### 总的来说,程序员越自由,程序性能就越差 不过也有反例,我们之前那个程序就是. ~~~ //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 毫秒 } ~~~ 想想这是为什么?