Java和C++的性能对比

前两天水群,和别人扯到C++和Java的性能对比,感觉现在好多人已经不再说java慢了,甚至好多人认为java性能已经和C++差不多了。但是正好我司有个模块在尝试java转C++,这就引来大家的一片质疑,后来我在网上找到这样一份数据,大多数情况下C++无论在运行速度还是内存占用,比Java有更大的优势。
  最终,我们讨论的结论是,java这些年来在性能上提升了非常多,甚至平均性能已经与C++不相伯仲了,但是在某些对性能要求极高的情况下还是不及C++。也就是说C++的性能天花板要比Java高一些。但反过来,Java的开发效率和其生态也是C++没法比。
  整理后的数据如下,原文https://benchmarksgame-team.pages.debian.net/benchmarksgame/faster/java-gpp.html

reverse-complement

sourcesecsmemgzcpucpu load
Java3.32609,71221837.5464% 44% 44% 76%
C++ g++2.93980,71622804.5251% 23% 33% 51%

pidigits

sourcesecsmemgzcpucpu load
Java3.1337,3649383.3699% 2% 3% 4%
C++ g++1.894,3805131.882% 99% 4% 2%

fasta

sourcesecsmemgzcpucpu load
Java2.3242,21224736.3065% 85% 47% 76%
C++ g++1.331,74027114.2981% 81% 81% 82%

fannkuch-redux

sourcesecsmemgzcpucpu load
Java17.9831,180128270.5797% 99% 97% 99%
C++ g++10.121,85298039.95100% 100% 96% 100%

spectral-norm

sourcesecsmemgzcpucpu load
Java4.2633,57295016.3996% 96% 98% 95%
C++ g++1.981,16410447.8799% 99% 99% 100%

binary-trees

sourcesecsmemgzcpucpu load
Java8.39960,05683527.3981% 85% 74% 90%
C++ g++3.68119,05280911.9398% 76% 77% 78%

n-body

sourcesecsmemgzcpucpu load
Java22.0032,272148922.071% 0% 0% 100%
C++ g++9.421,70417639.412% 100% 1% 0%

k-nucleotide

sourcesecsmemgzcpucpu load
Java8.74470,116181227.1271% 73% 93% 74%
C++ g++3.73156,080162411.6075% 70% 72% 96%

mandelbrot

sourcesecsmemgzcpucpu load
Java6.9676,31679627.0697% 97% 97% 97%
C++ g++1.5125,64017915.99100% 100% 99% 99%

regex-redux

sourcesecsmemgzcpucpu load
Java10.50571,73692931.6371% 73% 66% 92%
C++ g++1.83203,52013154.4150% 45% 100% 49%

Java

openjdk 11 2018-09-25
OpenJDK Runtime Environment 18.9 (build 11+28)
OpenJDK 64-Bit Server VM 18.9 (build 11+28, mixed mode)

C++ g++

g++ (Ubuntu 8.2.0-7ubuntu1) 8.2.0

原文中还有Java vs C, Java vs C#,Java vs Substrate VM的对比,java和C就差更多了,但是和C#旗鼓相当。

xindoo CSDN认证博客专家 Linux 分布式 Spring
一个有趣有料的程序猿,9年技术博主,曾在阿里做过3年运维相关工作,现为某厂资深后端工程师,拥有丰富的挖坑踩坑填坑背锅经验[狗头],专注于Java,对操作系统、网络、编译原理也有涉猎。
微信号: zxs-io 添加注明CSDN
相关推荐
©️2020 CSDN 皮肤主题: 博客之星2020 设计师:CY__ 返回首页