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?
EricF - 25 Feb 2006 06:36 GMT
>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
[quoted text clipped - 10 lines]
>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
Oliver Wong - 27 Feb 2006 15:25 GMT
> 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.lang.java.programmer/msg/cea47d1ebb9c540a
> 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.lang.java.programmer/msg/cb5cfa858f8e09c5
> 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
tabun@storm.ca - 26 Jul 2006 08:54 GMT
> 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
[quoted text clipped - 10 lines]
> 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.
Oliver Wong - 27 Jul 2006 14:58 GMT
>> 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
[quoted text clipped - 3 lines]
>> 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.lang.java.advocacy/msg/4afdc4eda32ca731
>> 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