Java vs C++ speed (IO & Sorting)

D

dave_mikesell

I guess your g++ compiler is just better than my VC++ compiler for
this test :)

I'd say "test" is a bit too strong of a word here. "Fishing
expedition" makes more sense.
 
S

stan

Mark said:
Mostly I'm interested in the perceptions of the folks claiming that C++
is better. I'm sure that Java is fine, but I'd like to hear what the
other side has to say. So far they haven't deigned to respond....

Maybe you should seek that information in a group where it's on topic.
People acting like adults don't feed the trolls, just as they don't tap
on fish tanks.
 
M

Mark Thornton

stan said:
Maybe you should seek that information in a group where it's on topic.
People acting like adults don't feed the trolls, just as they don't tap
on fish tanks.

Is there a group read by people with good C++/Java skills where such
questions are on topic? There is no C/C++ equivalent to
comp.lang.java.advocacy (and I doubt many Java programmers bother with
that either).

Oh, and plenty of adults tap on fish tanks --- they've paid their money
and want to see the creatures move. I don't approve, but it certainly
happens.

Mark Thornton
 
J

jason.cipriani

Mostly I'm interested in the perceptions of the folks claiming that C++
is better. I'm sure that Java is fine, but I'd like to hear what the
other side has to say. So far they haven't deigned to respond....

I don't know what the terrain is like in comp.lang.java.programmer,
maybe we're more used to trolls in comp.lang.c++. I wouldn't pay too
much attention to Razii. Also it's like debates between "soda" and
"pop" or "Windows" and "Linux"... to which I say: oh lord, not
*again*.

FWIW, I'm a registered C++ programmer, however I find Java to be an
equally wonderful tool depending on the task. What I value most (among
many things) about C++ is that I can get close to the hardware using a
nice high-level syntax, and what I value most (also among many things)
about Java is its rich standard component library. I have never had
performance issues with either language, and I also have never had
problems expressing the program I want to write in either language
(especially since the introduction of Java generics).

Jason
 
E

Erik Wikström

Anyone making a statement that language X is better than Y is an idiot,
no language is always the best. However all languages have certain
characteristics that makes them more suitable for some purpose than
other languages, but in many cases the best language for a task is the
one you know best.
Is there a group read by people with good C++/Java skills where such
questions are on topic? There is no C/C++ equivalent to
comp.lang.java.advocacy (and I doubt many Java programmers bother with
that either).

When discussing the merits of different programming languages I think
that comp.programming might be a good place to start. Asking in a group
for a specific language is a sure way to be told that the language
discussed in the group is the best.
 
J

jason.cipriani

When discussing the merits of different programming languages I think
that comp.programming might be a good place to start. Asking in a group
for a specific language is a sure way to be told that the language
discussed in the group is the best.

And not only that, but like with many such discussions, most of the
content posted is from extremely opinionated authors, many who's
opinions are unlikely to change -- and so it biases the answers
towards the extremes. I think the vast majority of people might not
feel strongly either way, and these people, like me, don't really want
to get involved in circular discussions anyways. In other words, the
real most popular answer to a lot of these types of discussions is: it
doesn't matter. You'd never guess that by reading the discussions,
though.

Jason
 
C

Cory Nelson

I guess your g++ compiler is just better than my VC++ compiler for
this test :)

VC++ 2005 added in the notion of a "checked" standard library which
does bounds checking etc on iterators and can incur a large
performance hit in some cases. Please, add this to the top of the C++
file:

#define _SECURE_SCL 0

This is all a little silly. They both have adequate default
performance, so who cares about that. Maybe in some cases one is
better than the other, but after you've profiled if you decide
performance is lacking, when push comes to shove you will never be
able to hand-optimize Java like you can C++.

That's just one benefit of C++. Java has some benefits over C++ too.
Some people get too worked up when they learn that their favorite
language sometimes isn't the right tool for the all jobs.
 
M

Mark Thornton

Erik said:
When discussing the merits of different programming languages I think
that comp.programming might be a good place to start. Asking in a group
for a specific language is a sure way to be told that the language
discussed in the group is the best.

comp.programming seems all but defunct. My provider has a total of three
messages for this year and about 69 for the last 3 years. While there
are reasonable discussions to be had about the merits of different
languages for various tasks, I don't think there are any active
newsgroups that welcome such discussions. Only a moderated group could
maintain a quality discussion.

Mark
 
S

Sjouke Burry

Mark said:
comp.programming seems all but defunct. My provider has a total of three
messages for this year and about 69 for the last 3 years. While there
are reasonable discussions to be had about the merits of different
languages for various tasks, I don't think there are any active
newsgroups that welcome such discussions. Only a moderated group could
maintain a quality discussion.

Mark
You should check your provider.
I am reading that group the last few years, and have
daily between 5 and 25 messages(provider news.planet.nl)
New messagecount after about 5-10 minutes: 2
 
A

Arved Sandstrom

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:
[ SNIP ]

It was educational for me. I took the Java and C++ verbatim, compiled and
ran them on my machine (with the indicated optimization for C++), and got
averages of about 520-530 ms for C++, and about 390 ms for Java. It's worth
pointing out that a straightforward Haskell implementation compiled with GHC
6.8 averaged about 250-350 ms on my machine, and a J singleliner (about 25
characters of code less the filenames) averaged about 150-170 ms.

I throw those 2 examples in mostly because it shows that the C++ vs. Java
thing is a pissing match. The Haskell code is

----------------------------------------------------
module Main where
import qualified Data.ByteString.Lazy.Char8 as LC8
import Data.List (sort)
import System.Environment (getArgs)

main = do
(fn:_) <- getArgs
bs <- LC8.readFile fn
(LC8.writeFile (fileNameOut fn) . LC8.unlines . sort . LC8.lines) bs

fileNameOut fn = takeWhile (\c -> c /= '.') fn ++ ".out.txt"

----------------------------------------------------

and the J code is

(;/:~ <;.2 [1!:1 <filein) 1!:2 <fileout

The J code is easy to understand once you learn J (arguably no more
difficult than any other language), and who can complain about an
interpreted solution where the code takes about as long to write as the two
filenames? :)

The Haskell code is probably about as clean as code will get - it is
self-explanatory, and any programmer who's seen at least two or three
languages can figure out what it's doing.

So in this particular case I can't get too excited about a C++ vs. Java
comparison. In fact all four of the languages I tried here compare fairly
well, for _this_ problem, when one considers all factors.

AHS
 
M

Mark Thornton

Sjouke said:
You should check your provider.
I am reading that group the last few years, and have
daily between 5 and 25 messages(provider news.planet.nl)
New messagecount after about 5-10 minutes: 2

Mmm. The charter for comp.programming suggests that comp.lang.misc might
be a better match.

Mark.
 
I

Ian Collins

Mark said:
comp.programming seems all but defunct. My provider has a total of three
messages for this year and about 69 for the last 3 years.

Odd, NIN has almost 5000 for the year!
 
L

Lew

Im not sure if i [sic] used the right optimization flags to compile the
java [sic] program so if its wrong please tell me how i should compile it, since
i expected to obtain similar results.

You might try run-time flags, such as '-server', rather than compile-time
flags. Most Java program optimization occurs at run-time, not compile-time.

For this particular benchmark, which tries to be I/O bound, it might not
matter that much.
java -version:
java version "1.6.0_02"

You should upgrade your Java 6. A major security flaw was fixed in
sub-version _03, IIRC, and it's up to _05 now.
 
T

Tim Smith

Razii said:
What JVM did you use?

java version "1.5.0_13"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_13-b05-237)
Java HotSpot(TM) Client VM (build 1.5.0_13-119, mixed mode, sharing)
 
T

Tim Smith

Interpreted Perl whipped your Java version? Beware, you are about to
incur the Wrath of Razii!

Note that the task hit two things Perl is designed to be good at:

1. Reading an entire file and storing it line by line into an array.

2. Sorting an array.

I have not looked at how Perl is actually implemented, but I would not
be surprised if there was a C function down in Perl somewhere to slurp a
file into an array, and another to sort an array.
 
I

Ian Collins

Tim said:
Note that the task hit two things Perl is designed to be good at:

1. Reading an entire file and storing it line by line into an array.

2. Sorting an array.

I have not looked at how Perl is actually implemented, but I would not
be surprised if there was a C function down in Perl somewhere to slurp a
file into an array, and another to sort an array.
There probably is. As an experiment, I changed the C++ version to use
file mapping rather than iostreams to read the file. For the 10bible
test on my test machine, the time to read the file (without creating
strings) into a multiset changed from 1510ms to 570ms. So the
reading/sorting can certainly be optimised.
 
R

Razii

java version "1.5.0_13"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_13-b05-237)
Java HotSpot(TM) Client VM (build 1.5.0_13-119, mixed mode, sharing)

The new version is

C:\>java -version
java version "1.6.0_05"
Java(TM) SE Runtime Environment (build 1.6.0_05-b13)
Java HotSpot(TM) Client VM (build 10.0-b19, mixed mode, sharing)
 
R

Razii

Or perhaps alt.whine.

Do you know who is being whining. You and some of your fellow nuts. My
post was just right on the topic. What have you and some of your
fellow nuts have contributed instead of whining? If you have a problem
with the a topic, move on to the next thread moron. This is
unmoderated USENET newsgroup -- do you know what that means?
 
J

jason.cipriani

What have you and some of your
fellow nuts have contributed

Well, for starters, one study found that people who eat nuts live two
to three years longer than those who do not; however, I believe that
question is actually more appropriate for sci.agriculture.fruit.

Jason
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,179
Messages
2,570,956
Members
47,509
Latest member
Jack116

Latest Threads

Top