I made bible.txt 10 times and made it a 43 meg file
C++ is doing far worse now (the code used was multiset version)
Time for reading, sorting, writing: 2047 ms (java)
Time for reading, sorting, writing: 2016 ms (java)
Time for reading, sorting, writing: 2016 ms (java)
Time for reading, sorting, writing: 2015 ms (java)
and for c++
Time for reading, sorting, writing: 5281 ms (c++)
Time for reading, sorting, writing: 5703 ms (c++)
Time for reading, sorting, writing: 3921 ms (c++)
Time for reading, sorting, writing: 3718 ms (c++)
How come? c++ is at least 45% times slowe (if using 3718 ms)
I'm sure your deltas are not significant in terms of computer
architecture and maybe not statistically either. I've done other
benchmarks on JVM versions and you'll get variance based on disk IO.
once you run from RAM you get fairly comparable results but certainly
you'd need to drop to runlevel 1 or something (boot into ksh?) to get
close to a bare-metal comparison. Maybe that was discussed before as I
read only this posting.
Anyways, what I see is Java is fairly fast once it gets into RAM. Of
course you can code something faster in C (not C++ even). Some
companies used to even hand-code assembly! I'm sure the compiler,
compiler options, hardware architecture, etc. are a big factor in C/C+
+. Time was every major tech company had a compiler team just for that
reason. Until you have tailored the assembly output by the C code then
you are not being fair. E.g. the JVM is architecture dependent and
init'ed for that hardware at the time at which you start your clock.
You'd need to likewise have optimized assembly output for the C binary
to make an apples comparison. Not just compiled with -o or -g or
whatever but with architecture specific flags at least.
If you think performance is not too important anymore then you are
right. Modern OS's do not perform anywhere in the ballpark as fast as
old ones, for instance.
Best,
TimJowers