最近两个java 项目均是性能关键型。
影响性能的两个主要因素:
[list]
[*]算法
[*]实现
[/list]
结论:
对于内存丰富型,海量处理(服务器)应用,java 带来的性能损失(相对c++),不会超过20%。
这样的系统软件,用Java 并无不妥。
论据
为了支持以上结论, 列出如下论据
[list=1]
[*]block io , java 性能损失不超过20%
[*]sort 算法,不超过20%
[*]GC 问题,不超过20%
需要注意: 避免无谓的对象创建,避免无谓的反射,lazy initialize
[*]尽可能 concurrent
用 executor ,尽可能 concurrent .
需要concurrent 的类,提前考虑 threadSafe
[/list]
欢迎批评指正!建设性意见的更好。
ps:
今天重读了 《effective java 》
我最后还是确认了我的结论.
参见:http://jimcgnu.iteye.com/blog/54469
这是文中的测试结果。
Java C++
Fibonacci 10767 ms 7468 ms
Heapsort 5454 ms 4344 ms
NestedLoops 8022 ms 3453 ms
CopyData 1204 ms 1125 ms
代码也是有的。
引用:
I would admit that it is correct to say java is slower than c++ when it comes to primitve datatypes and optimizing nested loops but there are real objects also where the numbers may change somewhat. In fact it will depend upon the tasks.
顺便,说一声:
我是试图对比 bdb c edition vs java edition 's benchmark 的时候,发现这篇文档的。
ps;
The only two examples that I know of that have been implemented both in C++ (or C) and Java are http://www.bytonic.de/html/jake2.html (Jake2), a clone of Quake2 in Java, and http://cmusphinx.sourceforge.net/sphinx4.. (Sphynx), a speech recognizer first coded in C, then in Java. Jake2 performance in Java 5.0 are identical to the original C versions (in some configurations), and Sphynx4 (in Java) performs better than the C version.
add some interesting example.
http://code.google.com/p/hypertable/wiki/WhyWeChoseCppOverJava
> Would love to see the Oracle/Tangosol Coherence team discuss this as they > pretty much built their product as a large, distributed hashmap.
Language choice tends to be very personal, and usually defaults to what a programmer knows best, or is most comfortable with.
Despite working in C/C++ for years before Java, and continuing to work in C++ (no C anymore) today -- alongside C# and Java -- I would still default to Java for most things.
I don't know if the rationale given here makes sense, but in general, for a tightly focused product and a small development team that is comfortable working in C++, then C++ can certainly have a performance edge over Java (for most use cases).
Java is significantly better at "global optimizations" from a development perspective, which is to say that within a process (e.g. JVM), the boundary cost of Java (libraries, APIs, down to the interface level) is far lower than the cost of C++ as a project grows. (It's hard to explain if you haven't worked with large scale C++ projects that pull together multiple libraries and work from different groups.) The side-effect of this is often that the cost of development in Java does not rise as fast in correlation to the complexity of the product, and that the fn(quality,performance) does not drop as fast. However, while I would testify to this under oath, you will find the opposite opinion to be just as strongly believed by another programmer.
Peace,
Cameron Purdy Oracle Coherence
but,
Surely the development time arguments only apply if no-one really uses your software. As long as enough people use your software then even a marginal performance benefit is worth significant programming effort.
You wouldn't like it if Microsoft wrote Word in C# because it was slightly easier would you?
so critical issue is which quaility is enough.
影响性能的两个主要因素:
[list]
[*]算法
[*]实现
[/list]
结论:
对于内存丰富型,海量处理(服务器)应用,java 带来的性能损失(相对c++),不会超过20%。
这样的系统软件,用Java 并无不妥。
论据
为了支持以上结论, 列出如下论据
[list=1]
[*]block io , java 性能损失不超过20%
[*]sort 算法,不超过20%
[*]GC 问题,不超过20%
需要注意: 避免无谓的对象创建,避免无谓的反射,lazy initialize
[*]尽可能 concurrent
用 executor ,尽可能 concurrent .
需要concurrent 的类,提前考虑 threadSafe
[/list]
欢迎批评指正!建设性意见的更好。
ps:
今天重读了 《effective java 》
我最后还是确认了我的结论.
参见:http://jimcgnu.iteye.com/blog/54469
这是文中的测试结果。
Java C++
Fibonacci 10767 ms 7468 ms
Heapsort 5454 ms 4344 ms
NestedLoops 8022 ms 3453 ms
CopyData 1204 ms 1125 ms
代码也是有的。
引用:
I would admit that it is correct to say java is slower than c++ when it comes to primitve datatypes and optimizing nested loops but there are real objects also where the numbers may change somewhat. In fact it will depend upon the tasks.
顺便,说一声:
我是试图对比 bdb c edition vs java edition 's benchmark 的时候,发现这篇文档的。
ps;
The only two examples that I know of that have been implemented both in C++ (or C) and Java are http://www.bytonic.de/html/jake2.html (Jake2), a clone of Quake2 in Java, and http://cmusphinx.sourceforge.net/sphinx4.. (Sphynx), a speech recognizer first coded in C, then in Java. Jake2 performance in Java 5.0 are identical to the original C versions (in some configurations), and Sphynx4 (in Java) performs better than the C version.
add some interesting example.
http://code.google.com/p/hypertable/wiki/WhyWeChoseCppOverJava
> Would love to see the Oracle/Tangosol Coherence team discuss this as they > pretty much built their product as a large, distributed hashmap.
Language choice tends to be very personal, and usually defaults to what a programmer knows best, or is most comfortable with.
Despite working in C/C++ for years before Java, and continuing to work in C++ (no C anymore) today -- alongside C# and Java -- I would still default to Java for most things.
I don't know if the rationale given here makes sense, but in general, for a tightly focused product and a small development team that is comfortable working in C++, then C++ can certainly have a performance edge over Java (for most use cases).
Java is significantly better at "global optimizations" from a development perspective, which is to say that within a process (e.g. JVM), the boundary cost of Java (libraries, APIs, down to the interface level) is far lower than the cost of C++ as a project grows. (It's hard to explain if you haven't worked with large scale C++ projects that pull together multiple libraries and work from different groups.) The side-effect of this is often that the cost of development in Java does not rise as fast in correlation to the complexity of the product, and that the fn(quality,performance) does not drop as fast. However, while I would testify to this under oath, you will find the opposite opinion to be just as strongly believed by another programmer.
Peace,
Cameron Purdy Oracle Coherence
but,
Surely the development time arguments only apply if no-one really uses your software. As long as enough people use your software then even a marginal performance benefit is worth significant programming effort.
You wouldn't like it if Microsoft wrote Word in C# because it was slightly easier would you?
so critical issue is which quaility is enough.