Java vs C#:是否有任何研究比较它们的执行速度?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1049004/
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
Java vs C#: Are there any studies that compare their execution speed?
提问by pistacchio
Taking out all of the obvious caveats related to benchmarks and benchmark comparison, is there any study (an array of well documented and unbiased tests) that compares the average execution speed of the two mentioned languages? Thanks
除去与基准和基准比较相关的所有明显警告,是否有任何研究(一系列有据可查且无偏见的测试)比较了提到的两种语言的平均执行速度?谢谢
采纳答案by Rasmus Faber
The best comparison that I am aware of is The Computer Language Benchmarks Game.
我所知道的最好的比较是The Computer Language Benchmarks Game。
It compares speed, memory use and source code size for (currently) 10 benchmarks across a large number of programming languages. The implementations of the benchmarks are user-submitted and there are continuous improvements, so the standings shift around somewhat.
它比较了(当前)10 个跨大量编程语言的基准测试的速度、内存使用和源代码大小。基准测试的实现是用户提交的,并且不断改进,因此排名有所变化。
The comparison is currently openjdk vs C# .NET Core.
目前比较的是 openjdk 与 C# .NET Core。
Currently it is close, but .NET Core is slightly faster on most benchmarks.
回答by Wim ten Brink
This could invite a flamewar, but hey, it's my opinion...
First of all, if your site runs too slow, you'll need better hardware. Or more hardware and add load balancing to your site. If you're Google, you'll end up with huge server farms with thousands of machines that will seem to provide a lightning-fast performance, even if the sites themselves are developed in some outdated language.
Most languages have been optimized to get the best from their hardware and will outperform any other language in this specific environment with a specific setup. Comparing languages won't make much sense because there are thousands of techniques to optimize them even more. Besides, how do you measure performance to begin with?
Let's say that you look at execution speed. Language X might perform some task 2 times faster than language Y. However, language Y is more optimized for running multiple threads and could serve 10 times more users than language X in the same amount of time. Combine this and Y would be much faster in a client/server environment.
But then install X on an optimized system with an operating system that X likes a lot, with additional hardware, a gadzillion bytes of memory and disk space and a dozen or so CPU's and X will beat Y again.
So, what's the value of knowing the execution speed of languages? Or even the comparison of languages? How do we know that the ones who created the report weren't biased? How are we sure that they used the most optimal settings for every language? Did they even write the most optimal code to be tested? And how do you compare the end results anyways? Execution time per user? Or total execution time?
Back to languages X and Y. X runs a task in 2 seconds but it supports only 10 threads at the same time, thus 10 users. Y needs 6 seconds but serves up to 50 threads at the same time. X would be faster per user. In two seconds, X has processed 10 users. In 6 seconds, X has processed 30 users. But Y would have processed 50 users by that time. Thus Y would outperform X when you have lots of users, while X would out-perform Y with a low amount of users. (Or threads.) It would be interesting to see reports mentioning this, right?
这可能会引发一场激烈的战争,但是嘿,这是我的意见...
首先,如果您的网站运行速度太慢,您将需要更好的硬件。或更多硬件并为您的站点添加负载平衡。如果您是 Google,您最终会拥有拥有数千台机器的庞大服务器群,即使这些网站本身是用某种过时的语言开发的,这些机器似乎也能提供闪电般的性能。
大多数语言都经过优化,可以充分利用其硬件,并且在具有特定设置的特定环境中的性能将优于任何其他语言。比较语言没有多大意义,因为有成千上万种技术可以进一步优化它们。此外,您如何衡量绩效?
假设您查看执行速度。语言 X 执行某些任务的速度可能比语言 Y 快 2 倍。但是,语言 Y 更适合运行多线程,并且在相同的时间内可以为语言 X 服务的用户多 10 倍。在客户端/服务器环境中将这个和 Y 结合起来会快得多。
但是,然后将 X 安装在具有 X 非常喜欢的操作系统的优化系统上,加上额外的硬件、数十亿字节的内存和磁盘空间以及十几个左右的 CPU,X 将再次击败 Y。
那么,了解语言的执行速度有什么价值呢?甚至语言的比较?我们怎么知道创建报告的人没有偏见?我们如何确定他们对每种语言都使用了最佳设置?他们甚至编写了要测试的最佳代码吗?无论如何,您如何比较最终结果?每个用户的执行时间?还是总执行时间?
回到语言 X 和 Y。X 在 2 秒内运行一个任务,但它只支持 10 个线程同时,因此 10 个用户。Y 需要 6 秒,但同时提供多达 50 个线程。每个用户 X 会更快。在两秒钟内,X 处理了 10 个用户。在 6 秒内,X 处理了 30 个用户。但到那时 Y 已经处理了 50 个用户。因此,当您拥有大量用户时,Y 的表现会优于 X,而当用户数量较少时,X 的表现会优于 Y。(或线程。)看到提到这一点的报道会很有趣,对吧?
回答by Ohad Schneider
Here's a nice recent studyon the subject:
Numeric performance in C, C# and Java
Peter Sestoft ([email protected])
IT University of Copenhagen Denmark
Version 0.9.1 of 2010-02-19
Abstract:We compare the numeric performance of C, C# and Java on three small cases.
...
C、C# 和 Java 中的数值性能
彼得·塞斯托夫特 ([email protected])
丹麦哥本哈根信息技术大学
2010-02-19 0.9.1 版本
摘要:我们在三个小案例上比较了 C、C# 和 Java 的数值性能。
...
回答by Aleksandr Dubinsky
Both languages are evolving in terms of performance. At least in 2013, Microsoft's own Joe Duffy blogged:
这两种语言在性能方面都在不断发展。至少在 2013 年,微软自己的 Joe Duffy博客写道:
Java is closer [to C++ in performance] than C# thanks to the excellent work in HotSpot-like VMs which employ code pitching and stack allocation.
Java 比 C# 更接近 [在性能上接近 C++],这要归功于在类似 HotSpot 的 VM 中的出色工作,这些 VM 采用了代码投球和堆栈分配。