java Kotlin 是否提供任何性能提升?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/44081105/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Does Kotlin provide any performance boosts?
提问by Methnani Bilel
Does Kotlin provide any performance boosts? Is there any benchmarking? Is Kotlin faster than Java? I found this in the Kotlin website. https://kotlinlang.org/docs/reference/comparison-to-java.htmlTalking about the language features but not performance.
Kotlin 是否提供任何性能提升?有没有基准测试?Kotlin 比 Java 快吗?我在 Kotlin 网站上找到了这个。https://kotlinlang.org/docs/reference/comparison-to-java.html谈论语言特性而不是性能。
回答by yole
Kotlin generates very similar bytecode to Java, so the performance of Kotlin code is in most cases the same as the performance of the equivalent Java code.
Kotlin 生成的字节码与 Java 非常相似,因此 Kotlin 代码的性能在大多数情况下与等效的 Java 代码的性能相同。
One way in which Kotlin can be faster than Java is inline functions. With inline functions, code using higher-order functions such as filter
or map
can be compiled to simple loop-based bytecode that doesn't create any objects or use any virtual calls (unlike Java code that uses the same type of functions).
Kotlin 比 Java 更快的一种方式是内联函数。使用内联函数,使用诸如filter
或 之类的高阶函数的代码map
可以编译为简单的基于循环的字节码,该字节码不创建任何对象或使用任何虚拟调用(与使用相同类型函数的 Java 代码不同)。