PDA

View Full Version : Java Speed?


Nafae
02-23-2002, 11:30 PM
I have always gotten the impression that java applications are slow, but I was curious if this was just from the stuff I have ran and viewed, or is java traditionally a slow language?

kmj
03-05-2002, 12:25 PM
I think it has sped up pretty well in more recent releases of the language; though I have no quantitive proof of this. Certainly it won't match C in speed, though. :)

Fireman-x
03-05-2002, 05:02 PM
It also depends on how you're running it, and what you're running it on, as well as how you're using it. If you're using a JIT (Just In Time) compiler, you're speeds are going to be closer to C.

Dru Lee Parsec
03-05-2002, 06:34 PM
Java is an awesome language, and I firmly place myself on the side of the "Java Evangelist". However, we must remember that no language is the absolute king of all languages. So if we're talking about how Java is too slow to be used for writing Graphics drivers, then you're probably right. However, if you're writing a GUI application (Like Jext, the text editor I use every day.) then it's plenty fast.

In a past job we wrote an application in Java that did real time data translation of Navy Battle simulation messages (Each group of tanks, for example, would stream a set of messages stating where they were). We translated from one message type to another in real time.

On a Windows NT box the latency of each translation was about 12 milliseconds (although there were many translations going on at once on separate threads) The exact same computer was rebooted into Linux and the exact same code ran the exact same test data with a latency of only 40 milliseconds. So the OS certainly seems to have an effect on the speed of Java.

Also, there are programming techniques that can be used to speed up Java. Often, the perception that Java is slow is due to the speed of creating new Swing components. A common trick is to prebuild your gui in memory during the program start up (while the splash screen is showing) and then simply use setVisible(true) when you're ready to show a dialog.

So, is Java slower than C/C++? Certainly. Because Java is a partially compiled and partially interpreted language it will always be slower than code which is nativly compiled. However, it's good to remember 2 things:

1. With modern computers running at speeds in excess of a gig (combined with good programming practices) this speed differential can be reduced to the point of not even being noticable.
2. It's this very compile/interpreted schema which allows the exact same code base to run on Windows, Linux, SunOS, IBM AIX, and Mac OS X.

So, it's really a trade off of cross platform capability + ease of use vs. true speed. On some applications that's a trade off worth making. On others (like the video card driver example) then it's not an appropriate language.

I hope I explained that well. Let me know if something isn't clear.

P.S. Jext is available at www.jext.org It's a free Open Source coding text editor written in Java. If you want an editor that works exactly the same in Windows and Linux then Jext is a good choice.

Nafae
03-05-2002, 07:28 PM
Originally posted by Dru Lee Parsec
P.S. Jext is available at www.jext.org It's a free Open Source coding text editor written in Java. If you want an editor that works exactly the same in Windows and Linux then Jext is a good choice.

I downloaded that, and let me say that it is fantastic! The gui looks great, when I tried some php code, it quickly points out when you close a tag what the opening tag is by giving it a quick highlight. Very detailed, and allows you to use different code 'templates' available from a drop down menu. :tu: I think I just found an alt. to editplus...

Dru Lee Parsec
03-05-2002, 08:35 PM
Wow! I'm so glad you like it. Do you like the block comment and uncomment function? (I wrote that)

Nafae
03-05-2002, 08:59 PM
Originally posted by Dru Lee Parsec
Wow! I'm so glad you like it. Do you like the block comment and uncomment function? (I wrote that)

You helped write that program? I am even more impressed! I'll make sure to check out the functions you mentioned ASAP.

Edit: I was changing all my files to use Jedit (Right click, open with...) I had set it to go to C:\program files\jext\bin\jext.exe (or something to that extent) But when I open the files that I had changed, it opens up an empty "ok" box, and all I can do is click ok. Is there any other way to default programs to opening with Jext, or am i not setting it to open by default with the proper file?

kmj
03-06-2002, 12:50 AM
knew I'd getcha, dru :) Good to seeya posting.

gary_r_james
03-15-2002, 10:59 PM
Dru,

Here is a quote from one of your postings:

On a Windows NT box the latency of each translation was about 12 milliseconds (although there were many translations going on at once on separate threads) The exact same computer was rebooted into Linux and the exact same code ran the exact same test data with a latency of only 40 milliseconds. So the OS certainly seems to have an effect on the speed of Java.


From the numbers NT ran the app faster, but your grammar makes it sound as though the linux box was fast. Is 40 milliseconds a typo or was NT actually faster?

Thanks,

Gary

Dru Lee Parsec
03-17-2002, 04:49 PM
My mistake, it was suppose to be 120 milliseconds on NT and 40 on Linux

travix
03-27-2002, 02:57 PM
P.S. Jext is available at www.jext.org It's a free Open Source coding text editor written in Java. If you want an editor that works exactly the same in Windows and Linux then Jext is a good choice.

if you want to check out another good windows editor, download UltraEdit 32 from download.com it works nicely with many languages

Dru Lee Parsec
04-02-2002, 07:37 PM
I just wrote this for a challange over at the Java Ranch Big Moose Saloon. This code created an array of 1 million integers and then randomizes them. The randomization of 1 million int's takes 343 milliseconds on my P111 1Ghz



import java.util.*;

public class RandomTest {

private static int initialCapacity = 1000000;
private static int[] list = null;

public static void main(String[] args) {
list = new int[initialCapacity];
for (int i= 0;i< initialCapacity ;i++ ) {
list[i] = i;
}

Random random = new Random();
Date date1 = new Date();
long time1 = date1.getTime();
// now randomize them
for (int j= 0;j< initialCapacity ;j++ ) {
int x = random.nextInt(initialCapacity);
if (j != x) {
int t = list[j];
list[j] = list[x];
list[x] = t;
}
}

Date date2 = new Date();
long time2 = date2.getTime();
long delta = time2 - time1;
System.out.println("randomizing " + initialCapacity + " numbers took : " + delta + " milliseconds");

System.out.println("Here are the first 100");
for (int p=0;p<10;p++ ) {
for (int q=0;q<10;q++ ) {
System.out.print(list[(p*10)+q] + " ");
}
System.out.println("");
}
}
}


I think 343 milliseconds is pretty fast. :)