By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,070 Members | 1,238 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,070 IT Pros & Developers. It's quick & easy.

How fast is Java?

P: n/a
Many must have asked that question. I intend to write a few programs
which will be CPU intensive. I know a little of Java. Would a language
that yields native code, instead of bytecode perfrom much faster?

I recently wrote a minuscule C program containing one loop using a few
variables, and an equivalent java program, which was nearly as fast as
the C program. Unexpected result to me. When is Java slower?

What kind of program will I write? Programs for myself only. Only text,
no graphical user interface; batch processing; virtually no I/O. Mostly
comparing, and adding integers. Random access to memory.

Should I use my already installed Javac, or consider using another
language?

Feb 25 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
In article <43**************@sympatico.ca>, =?iso-8859-1?Q?Jean=2DFran=E7ois?= Blais
<je****************@sympatico.ca> wrote:
Many must have asked that question. I intend to write a few programs
which will be CPU intensive. I know a little of Java. Would a language
that yields native code, instead of bytecode perfrom much faster?

I recently wrote a minuscule C program containing one loop using a few
variables, and an equivalent java program, which was nearly as fast as
the C program. Unexpected result to me. When is Java slower?

What kind of program will I write? Programs for myself only. Only text,
no graphical user interface; batch processing; virtually no I/O. Mostly
comparing, and adding integers. Random access to memory.

Should I use my already installed Javac, or consider using another
language?

This is a question that's difficult to answer. If you were using a lot of
floating point, I'd say Fortran. But who wants to program in Fortran? Not me.
But if you have a lot of number crunching, it's a good choice.

Since these are personal programs, use the language you know if it's fast
enough. If it's not, then look for another. Well written C programs tend to be
very fast. But string processing in C is a pain. Actually it's a pain in Java
(and I like Java). But if I had to do a lot of text processing, I'd probably
look at Perl. (And I don't like Perl. Nothing wrong with it - it's a personal
preference.)

Early versions of the the JDK were certainly slower than C, and Java got a
reputation for being slow. That is no longer than case. The optimizers are a
lot better. But the results will vary with the cpu you use, the program
version, memory, operations ...

If you decide to go with Java, use at least version 1.4x. We have no idea what
version is installed on your machine. (java -version)

Eric
Feb 25 '06 #2

P: n/a
"Jean-François Blais" <je****************@sympatico.ca> wrote in message
news:43**************@sympatico.ca...
Many must have asked that question. I intend to write a few programs which
will be CPU intensive. I know a little of Java. Would a language that
yields
native code, instead of bytecode perfrom much faster?
Not nescessarily. See
http://groups.google.ca/group/comp.l...a47d1ebb9c540a
I recently wrote a minuscule C program containing one loop using a few
variables, and an equivalent java program, which was nearly as fast as the
C
program. Unexpected result to me. When is Java slower?
Very rarely. See
http://groups.google.ca/group/comp.l...5cfa858f8e09c5
What kind of program will I write? Programs for myself only. Only text, no
graphical user interface; batch processing; virtually no I/O. Mostly
comparing, and adding integers. Random access to memory.

Should I use my already installed Javac, or consider using another
language?


Use the programming language with which you are most comfortable.
Developper time (i.e. how much time you spend working on the project) is
more valuable than CPU time (i.e. how much time your CPU spends running the
program).

- Oliver

Feb 27 '06 #3

P: n/a
Jean-François Blais wrote:
Many must have asked that question. I intend to write a few programs
which will be CPU intensive. I know a little of Java. Would a language
that yields native code, instead of bytecode perfrom much faster?

I recently wrote a minuscule C program containing one loop using a few
variables, and an equivalent java program, which was nearly as fast as
the C program. Unexpected result to me. When is Java slower?

What kind of program will I write? Programs for myself only. Only text,
no graphical user interface; batch processing; virtually no I/O. Mostly
comparing, and adding integers. Random access to memory.

Should I use my already installed Javac, or consider using another
language?
Try gcj-4.1.
I have been playing with gcj-4.1 and have been writing up my discoveries
at the following url:
http://www.storm.ca/~tabun/
Do text search for "gcj" and you will find info to support you in your
adventures with compiling java natively.
You will find tar.gz's for examples that compile tcp/ip, awt, swt,
glade/gtk, aes(that's math and memory work which is what you like),
cortado, and finally a clarification of -cp and -foutput-class-dir=. in
order to compile stuff without getting all sorts of "type not found" errors.

Keep in mind my goal was to isolate everything and keep everything
simple to understand without resorting to an IDE or ant.
Mastery of -cp and -foutput-class-dir=. will permit developers to put
java sources into makefiles with all the rest of the sources if you so
choose.

You can squeeze more performance with extra optimization switches which
you can read up in the gcj/gcc documentation.

I wish you lots of fun in your discoveries.
Jul 26 '06 #4

P: n/a

<ta***@storm.cawrote in message
news:WM******************************@storm.ca...
Jean-François Blais wrote:
>Many must have asked that question. I intend to write a few programs
which will be CPU intensive. I know a little of Java. Would a language
that yields native code, instead of bytecode perfrom much faster?

I recently wrote a minuscule C program containing one loop using a few
variables, and an equivalent java program, which was nearly as fast as
the C program. Unexpected result to me. When is Java slower?
See
http://groups.google.com/group/comp....fdc4eda32ca731
>>
What kind of program will I write? Programs for myself only. Only text,
no graphical user interface; batch processing; virtually no I/O. Mostly
comparing, and adding integers. Random access to memory.

Should I use my already installed Javac, or consider using another
language?
I'd recommend you write in whatever language you are most comfortable in
(unless your goal is to learn Java, in which case, write them in Java).
Don't worry about optimization until you actually notice a problem in
performance. And then, look at optimizations at the algorithm and data
structure levels before worrying about switching to a "faster" language.

- Oliver

Jul 27 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.