Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
C++
Java vs C++ speed (IO & Sorting)
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
Reply to thread
Message
[QUOTE="Michael.Boehnisch, post: 3488890"] Hi! The atmosphere in this whole thread is already beyond my usual "ok- thats-it-i-am-out" threshold. There is nothing wrong with heated discussion, I enjoy it. It would be nice, though, if everybody came back to civilized manners here. Childishly pointing out irrelevant typos in example code goes nowhere, neither do insults or wild accusations. The original post was provocative but not rude - and he has a valid point in comparing *aspects* of Java performance to C++ performance. Please remember, programming languages are tools, not holy sacraments. 'Nuff said, back to business: The C++ equivalent to this bread-and-butter fragment is: std::ofstream fstream( "prime.txt" ); No need to explicitly construct three objects. IMHO, Java is overdoing interface separation here a little bit. I am sure, though, most serious Java programmers will have wrappers for stuff like this in their private utility and code snippet collection. I am doing this for C and C++ for twenty years already - my personal toolbox is nearly 800 classes of reusable code already, saves me lots of time in projects i am doing. Arbitrary length integer math is not part of the "standard" C++ library, but there are plenty of widely adopted packages that offer such functions and its not really hard to implement. I do not think this example does you very well. probablePrime() is a *very* special purpose function of use maybe for cryptographic algorithm implementations. Traditionally, the standard libraries for C and C++ try to restrict themselves to functions of wide applicability and leave rare needs to independent, non-standardized third-party packages. This is a matter of style, not programming language powers. probablePrime() is limited in use since there is no guarantee the numbers it generates are *really* prime. In use cases where I have to rely vitaly on the prime number property, I cannot accept that e.g. 1 out of 1,000,000 generated numbers is pseudo-prime only. The implementation of a function like this is not super difficult also - take any arbitrary length integer package, generate some random numbers in a loop and check for primality property e.g. by Rabin's probabilistic test ten times. I'll sketch the C++ code out for, maybe in a private email conversation, if you're really interested. No, it doesn't - it generates ten 1000 bit numbers that are *likely* to be prime. They are good candidates for a more thorough checking with a deterministic method. This will need extra code and takes way more CPU time, though. It's not a trivial task to do it efficiently in any programming language. This is not a good basis. I am certain, in some obscure corner of the standard C++ library I'd be able to find something that is not directly available in the Java library and needs a custom implementation to reproduce. I admit, the Java library is *huge*. But I also like the "99-1" approach of the C++ library (99% of all problems is covered by 1% of library function candidates :-). Personal preference, nothing I'd put in good/bad categories. best, Michael [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
C++
Java vs C++ speed (IO & Sorting)
Top