【每日一翻】曾经有面试官问过我一个 Java 和 Python 谁更快的问题。这个问题的最佳答案是什么?这个面试官真正想问的是什么?

题图

问:曾经有面试官问过我一个JavaPython谁更快的问题。这个问题的最佳答案是什么呢?这个面试官真正想问的又是什么呢?
答:这个问题有三个答案:错误答案菜鸟的答案老鸟的答案

  • 错误答案: Python是一门比较新的语言,它很酷,每个人都在用它。而Java是一门过时的语言。因此Python更快。
  • 菜鸟的答案: Java更快。因为它有更快的VM—虚拟机,支持多线程,吧啦、吧啦、吧啦
  • 老鸟的答案:这个问题毫无意义。JavaPython是编程语言,快和慢并不适合用来形容它们,问这个问题就像问英语和德语谁更快一样。而快和慢是用来形容程序的,这两个语言都可以写出快程序和慢程序。除此之外,速度还取决于运行程序的硬件。一个跑在低性能机器上的”快速”的Java程序,会比一个跑在高性能机器上的Python程序跑得更慢。如果你有现成的程序,我们可以测量它们的性能,通过数据来比较它们的快慢。

原文出自一个不存在的网站,内容如下:

There are three answers to this question: the wrong answer, the beginner answer, and the experienced answer.
The wrong answer is: Python is a newer language that’s pretty cool and everybody’s using it and Java is old-fashioned so Python is faster.
The beginner answer is: Java is faster because it has a fast VM and multiple threads and techy, techy, techy.
The experienced answer is: Your question doesn’t make sense. Java and Python are languages. Faster or slower does not apply to them. It’s like asking which is faster, English or German? Faster or slower applies to programs. It’s possible to write fast or slow programs in either language. In addition, speed depends on the hardware that the program runs on. A “fast” Java program on a slow machine may be slower than a “slow” Python program on a fast machine. If you have specific programs in mind, we can measure their performance and see how they compare.