Is JDK1.4.0 compiled code faster than JDK1.3.1?
I'm compiling my code using JDK1.3.1, but I'm running it using JRE1.4.0. If I compile all of my code using JDK1.4.0, should I expect a performance boost? Particularly in terms of GUI components?
The reason I haven't compiled in JDK1.4.0 is because I'm using Forte, and it has some major Form Editor bugs when running with JDK1.4.0, so I can't use it at this time.
Thanks.
Hi, referring to the latest Java Live Session (High Performance GUIs With the JFC/Swing API, http://developer.java.sun.com/developer/community/chat/JavaLive/2002/jl0423.html), you will get better performance, although "boost" would be quite optimistic.
Here's a snipped from that session:
"... SeanOfVA: Are the performance improvements in v1.4 such that a Swing application compiled with v1.3.x, but executed in a v1.4 JVM would exhibit improved performance? There are a variety of reasons I would prefer not to incorporate 1.4 features yet into my source code base.
WilsonSD: Absolutely. For starters look at the Performance and Scalability Guide [http://java.sun.com/j2se/1.4/performance.guide.html]. Specifically, the enhancements in Java2D will provide nice speed-ups for typical Swing apps in terms of GUI responsiveness. The 2D pipeline architecture allows for faster performance on many graphics operations. Since Swing uses J2D your Swing application benefits. Also, the Swing "back buffer" was rewritten to use the new 2D VolitileImage class. This will give many parts of your Swing application access to hardware acceleration without recoding..."
Patrick
Similar Messages
-
Is this logging code faster than using a standard logging API like log4J
is this logging code faster than using a standard logging API like log4J or the logging API in java 1.4
As you can see my needs are extremely simple. write some stuff to text file and write some stuff to dos window.
I am thinking about using this with a multi threaded app. So all the threads ~ 200 will be using this simultaneously.
* Tracer.class logs items according to the following criteria:
* 2 = goes to text file Crawler_log.txt
* 1 = goes to console window because it is higher priority.
* @author Stephen
* @version 1.0
* @since June 2002
import java.io.*;
import java.net.*;
import java.util.*;
import java.text.*;
class Tracer{
public static void log(int traceLevel, String message, Object value)
if(traceLevel == 1){
System.out.println(getLogFileDate(new Date()) +" >" + message+ " value = " + value.toString()););
}else{
pout.write(getLogFileDate(new Date()) +" >" + message + " value = " + value.toString());
pout.flush();
public static void log(int traceLevel, String message )
if(traceLevel == 1){System.out.println(message);
}else{
pout.write(message ) ;
pout.flush();
//public static accessor method
public static Tracer getTracerInstance()
return tracerInstance;
private static String getLogFileDate(Date d )
String s = df.format(d);
String s1= s.replace(',','-');
String s2= s1.replace(' ','-');
String s3= s2.replace(':','.');
System.out.println("getLogFileDate() = " + s3 ) ;
return s3;
//private instance
private Tracer(){
System.out.println("Tracer constructor works");
df = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM);
date = new java.util.Date();
try{
pout = new PrintWriter(new BufferedWriter(new FileWriter("Crawler_log"+getLogFileDate(new Date())+".txt", true)));
pout.write("**************** New Log File Created "+ getLogFileDate(new Date()) +"****************");
pout.flush();
}catch (IOException e){
System.out.println("**********THERE WAS A CRITICAL ERROR GETTING TRACER SINGLETON INITIALIZED. APPLICATION WILL STOP EXECUTION. ******* ");
public static void main(String[] argz){
System.out.println("main method starts ");
Tracer tt = Tracer.getTracerInstance();
System.out.println("main method successfully gets Tracer instance tt. "+ tt.toString());
//the next method is where it fails - on pout.write() of log method. Why ?
tt.log(1, "HIGH PRIORITY");
System.out.println("main method ends ");
//private static reference
private static Tracer tracerInstance = new Tracer();
private static Date date = null;
private static PrintWriter pout = null;
public static DateFormat df = null;
}In general I'd guess that a small, custom thing will be faster than a large, generic thing with a lot of options. That is, unless the writer of the small program have done something stupid, og the writer of the large program have done something very smart.
One problem with java in this respect is that it is next to impossible to judge exactly how much machine-level processing a single java statement takes. Things like JIT compilers makes it even harder.
In the end, there is really only one way to find out: Test it. -
How can floating point division be faster than integer division?
Hello,
I don't know if this is a Java quirk, or if I am doing something wrong. Check out this code:
public class TestApp
public static void main(String args[])
long lngOldTime;
long lngNewTime;
long lngTimeDiff;
int Tmp;
lngOldTime = System.currentTimeMillis();
for( int A=1 ; A<=20000 ; A++)
for( int B=1 ; B<=20000 ; B++)
Tmp = A / B;
lngNewTime = System.currentTimeMillis();
lngTimeDiff = lngNewTime - lngOldTime;
System.out.println(lngTimeDiff);
}It reports that the division operations took 18,116 milliseconds.
Now check out this code (integers replaced with doubles):
public class TestApp
public static void main(String args[])
long lngOldTime;
long lngNewTime;
long lngTimeDiff;
double Tmp;
lngOldTime = System.currentTimeMillis();
for( double A=1 ; A<=20000 ; A++)
for( double B=1 ; B<=20000 ; B++)
Tmp = A / B;
lngNewTime = System.currentTimeMillis();
lngTimeDiff = lngNewTime - lngOldTime;
System.out.println(lngTimeDiff);
}It runs in 11,276 milliseconds.
How is it that the second code snippet could be so much faster than the first? I am using jdk1.4.2_04
Thanks in advance!I'm afraid you missed several key points. I only used
Longs for measuring the time (System.currentTimeMillis
returns a long). Sorry you are correct I did miss that.
However, even if I had, double is
also a 64-bit data type - so technically that would
have been a more fair test. The fact that 64-bit
floating point divisions are faster than 32-bit
integer divisions is what confuses me.
Oh, just in case you're interested, using float's in
that same snippet takes only 7,471 milliseconds to
execute!Then the other explaination is that the Hotspot compiler is optimizing the floating point code to use the cpu floating point instructions but it is not optimizing the integer divide in the same way. -
Hi,
as long as RHEL-5 and then OEL-5 have been released, I have been wondering why my own programs, compiled and run on RHEL-5/OEL-5, are slower than the same programs compiled and run on RHEL-4/OEL-4 on the same machine. This is really barmy since gcc-4.1, shipped with RHEL-5/OEL-5, is very aggressive compiler and produces faster binary code than gcc-3.4.6, shipped with RHEL-4/OEL-4. I verified this hundred times testing both compilers on RHEL-4/OEL-4 and RHEL-5/OEL-5. The 4.1 compiler always produces faster executable on the same OS.
The problem is obviously in kernel-2.6.18. There is something in the kernel (maybe scheduler?) that slows down the execution of programs. But what? I experimented with changing various kernel boot parameters (eg "acpi=off" etc), even tried to recompile the kernel many times with various combinations of config parameters, and nothing helps. Thus, I'm still wondering whether the problem is solvable by disabling one or more config parameters and recompiling the kernel, or is deeply embedded in the main kernel code.
Is there anybody in this forum who experienced the same, say running OEL-4 before migrating to OEL-5?
Here are two examples showing different execution times on OEL-4.5 (kernel-2.6.9-55.0.5.0.1.EL.i686, gcc-3.4.6-8.0.1) and OEL-5 (kernel-2.6.18-8.1.10.0.1.el5, gcc-4.1.1-52.el5.2). The first example is trivial but very sensitive to overal system load and kernel version. The second example is "Sieve of Eratosthenes" - the program for finding prime numbers (CPU bound).
EXAMPLE 1.
/* Simle program for text screen console */
/* very sensitive to overall system load */
/* and kernel version */
#include <stdio.h>
int main(void)
register int i;
for(i = 0; i < 1000000; i++)
printf(" %d ", i);
return 0;
/* end of program */
$ gcc -O2 -o example1 -s example1.c
$ time ./example1The average execution times on OEL-4.5 and OEL-5 are as follow:
Mode OEL-4.5 OEL-5
real 0m3.141s 0m4.931s
user 0m0.394s 0m0.366s
sys 0m2.747s 0m4.563s
----------------------------------As we can see, the program on the same machine, compiled and run on OEL-4.5 (gcc-3.4.6 and kernel-2.6.9) is 57% faster than the same program compiled and run on OEL-5 (gcc-4.1.1 and kernel-2.6.18), although gcc-4.1.1 produces much faster binary code. Since the times the process spent in user mode are almost equal on both OS, the whole difference is due to the time the process spent in kernel mode. Note that kernel mode (sys) is taking 66% more time on OEL-5. It tells me that "something" in the kernel-2.6.18 slows down the execution of the program.
In the second example OEL-4.5 is also faster than OEL-5, but the differences in execution times are not so drastic as in the first example.
EXAMPLE 2.
/* Sieve of Eratosthenes */
#define GNUSOURCE
#include <stdio.h>
#include <stdlib.h>
#define MAX_PRIME_AREA 100000
#define REPEAT_LOOP 10000
int main(void)
int prime, composite, count;
char *sieve_array;
if ((sieve_array = (char *) malloc( (size_t) (MAX_PRIME_AREA + 1))) == NULL)
fprintf(stderr,"Memory block too big!\nMemory allocation failed!\a\n");
exit(EXIT_FAILURE);
for(count = 0; count < REPEAT_LOOP; count++)
for(prime = 0; prime < (MAX_PRIME_AREA + 1); prime++)
*(sieve_array + prime) = (char) '\0';
for(prime = 3; prime < (MAX_PRIME_AREA + 1); prime += 2)
if (! *(sieve_array + prime) )
*(sieve_array + prime) = (char) 'P'; /* offset prime is a prime */
for(composite = (2 * prime); composite < (MAX_PRIME_AREA + 1); composite += prime)
*(sieve_array + composite) = (char) 'X'; /* offset composite is a composite */
/* DO NOT COMPILE FOR TEST !!!
fprintf(stdout, "\n%d\n", 2);
for(prime = 3; prime < (MAX_PRIME_AREA + 1); prime += 2)
if ( *(sieve_array + prime) == 'P' )
fprintf(stdout, "%d\n", prime);
free(sieve_array);
return 0;
/* End of Sieve of Eratosthenes */The average execution times on the same machine on OEL-4.5 and OEL-5 are:
MAX_PRIME_AREA Mode OEL-4.5 OEL-5
real 0m9.196s 0m10.531s
100000 user 0m9.189s 0m10.478s
sys 0m0.002s 0m0.010s
real 0m20.264s 0m21.532s
200000 user 0m20.233s 0m21.490s
sys 0m0.020s 0m0.025s
real 0m30.722s 0m33.502s
300000 user 0m30.684s 0m33.456s
sys 0m0.024s 0m0.032s
real 1m10.163s 1m15.215s
400000 user 1m10.087s 1m14.704s
sys 0m0.075s 0m0.079s
---------------------------------------------------------Does this ring a bell with anyone? Any clue why?
N.J.An hour? Hard to believe or is your hardware that
old?An hour? That's a super good time for 3 kernel
packages (i686, xen and PAE) with all modules, plus 3
kernel-devel packages, plus debuginfo package of
150-580 MB where smart people at Red Hat decided to
put uncompressed vmlinux image which is necessary for
kernel profiling and debugging. Ah, I had a different kernel make process in mind.
Oracle doesn't ship
debuginfo package. Of course, this is when I build a
"complete suite" of kernel rpm packages using
unmodified spec file. And, to be honest, it takes
much more than an hour, maybe even two hours. Another
thing is compiling single i686 kernel without
building a package. But it also takes at least half
an hour. Anyway the time significantly depends on how
many modules are selected to be built in.That what I was looking for.
What's your time to build a single kernel (which
version?) with default set of modules ? On which
hardware ? I've only access to a root server right now, which is
cat /proc/cpuinfo | grep "model name"
model name : AMD Athlon(tm) 64 Processor 3700+with about 2GB of RAM
free -m
total used free shared buffers cached
Mem: 2024 1957 67 0 368 1291
-/+ buffers/cache: 297 1727
Swap: 3827 24 3803under
uname -a
Linux base 2.6.22-gentoo-r5 #5 PREEMPT Mon Sep 10 22:32:37 CEST 2007 i686 AMD Athlon(tm) 64 Processor 3700+ AuthenticAMD GNU/LinuxThis is what i did
cd /usr/src/linux
make clean
time nice -n 19 genkernel --lvm2 --makeopts="-j2" --oldconfig all
* Running with options: --lvm2 --makeopts=-j2 --oldconfig all
* Linux Kernel 2.6.22-gentoo-r5 for x86...*
mount: /boot mounted successfully!
* config: >> Running oldconfig...
* config: --no-clean is enabled; leaving the .config alone.
* >> Compiling 2.6.22-gentoo-r5 bzImage...
* >> Compiling 2.6.22-gentoo-r5 modules......
real 17m30.582s
user 16m8.480s
sys 1m9.000sWhat could helped here was that I've switched off some modules and (maybe) the use of ccache.
C. -
I understand that a XSL transformation is faster than JSP
Hi all
let's say the datasource solution provides data ,
I'm under the impression that you can make the XSL loop through the information do various logic on the data and represent the data much faster than can be accomplished with JSP
Is there anyone else out there that understands the same ?
stevI tend to doubt it. The XSL is interpreted (well, usually) where as the JSP is compiled. Sure, you can write really bad JSP code that underperforms really good transforms, but I'd tend to believe that in general it would be faster than XSL.
That said, XSL can provide for greater flexibility than JSP rendering and that may be easily worth any small performance penalty it may have.
Chuck -
How can I get tracks to play faster than normal speed in itunes?
I have lectures, audio books, and other recordings that I would like to play at faster than normal speed (like 1.5X or 2X normal speed). I've set all of these recordings as audio books because I read that they have the option to play faster, but, I can't find how to actually make them play faster. I also read that it's possible to open them in quicktime, but that is very much less than ideal and a waste of time. Surely there is a way to do this in itunes, but I can't figure it out.
Thanks for any help.I will show you how I played my audio or mp3 files at any particular speed. This method will allow you to simply enter in your desired speed.(ex. 1.5 or 1.33)
In my case Im using an audio book [Lord of the flies] I download off youtube as a MP3 file using this program:
http://download.cnet.com/MediaHuman-YouTube-to-MP3-Converter/3000-2140_4-7544580 3.html
First off, you will need to make sure your audio file is open in QuickTime player rather then iTunes. First you need to locate the audio file. If your audio file is in itunes then right click the file and select "Show in Finder"
The file should open in a finder window, highlighted. Right click the file, go to "Open With.." And click Quicktime Player. (If quickTime Player is not an option, you need to go to "Other..." and select QuickTime Player from your Applications folder)
Now that your mp3 file is open in a QuickTime window you may proceed to step 1.
1) Open Finder
2) Click Applications
3) Click Utilities
4) Open AppleScript Editor
5) In the program copy and paste the script below.
6) Click "Compile"
7) Now to test this script, click "Run" A window should pop up prompting you to enter your desired speed (default is 1.5)
8) press "OK" and quick time should start playing your audio at the speed you entered in.
9) If you would like to use this script again, go to File > Save... >Name your AppleScript and save it Anywhere (I saved mine in the Music Folder for easy access)
tell application "iTunes"
pause
set myTrack to location of current track
# the player’s position within the currently playing track in seconds
set mySeconds to player position
end tell
# show a Dialog
set SpeedFactor to 1.5
display dialog "Enter speed factor:" default answer SpeedFactor
set SpeedFactor to text returned of the result
tell application "QuickTime Player"
activate
# pause all previously opened documents
set open_docs to documents
repeat with doc in open_docs
pause doc
end repeat
# open the track just played in iTunes
open myTrack
# get the 'QuickTime' document, MyTrack should be equivalent but it isn't
set MyMovie to first document
# rewind by 10 seconds
if mySeconds > 10 then
set mySeconds to mySeconds - 10
end if
# set current time
set current time of MyMovie to mySeconds
# set Speed Factor and start playing
set rate of MyMovie to SpeedFactor
end tell -
Why is JVM faster than CLR?
hi
i wrote a N-body algorithm in both Java and C# (shown below). i executed it using .NET CLR and JDK1.4.1. in JDK it is twice as fast as .NET (on win2000). now i am trying to find out why is it so??
the interesting thing is that i ran some other algorithms like FFT and graph alogrithms, and they are faster in .NET. so i want to find is there some operation in the below algorithm that is making it run faster in JDK.
in general, what can the possible reasons be for JVM to run faster than CLR?
thanks
double G = 6.6726E-11;
double difference = 0.0;
for(int i=0; i<numBodies; i++)
accelarations[i] = 0.0;
for(int j=0; j<numBodies; j++)
if(i != j)
difference = radii[i] - radii[j];
if(difference != 0)
accelarations[i] += masses/(Math.pow(difference, 2));
accelarations[i] *= G;Interesting N-Body problem that treats accelerations as scalars.
Anyway, if there is no optimisation for small integer powers in the Math.pow() method, then I'd expect almost all the time is used there or in its equivalent in .NET. Hardly a meaningful test of relative performance.
Try using (difference * difference) instead.
Sylvia. -
"tp import all" runs 24 times faster than "tp import TR " for long queue?
After a test upgrade to ECC 6.0, I processed 1200 individual transports in 12 hours. When I rebuilt the queue of 1200 transports and processed "tp import all", it completed in 30 minutes.
Should I expect "tp import all" to process 24 times faster than individual imports?
800 transports were client independent (code) and 400 transports were client-specific (configuration).
What run times have you seen?
What problems with "tp import all" have you seen?
Best regards,
Gary SherwoodHi Gary
You don't know the 800 transports which are wating for the import, what could be render your system in case of import all. so, that's why , i will prefer to you import individual request instead of import all.
offcourse, Import all are faster than the individual because it prepare all steps once to start import,
Regards
Anwer Waseem -
I would like to ask if you guys could make a Compiler Code Generation API. This would allow developers who would like to fine-tune details you guys probably don't have time to do, for projects we think its important on. Specifically with [Bindable] and {} code generation.
I would like to be able, and many others I'm sure, to turn Binding on/off (conditional binding), and add more complicated expressions, but that's currently impossible, unless I rewrote the core UIComponent and everything. Or unless I had access to the generated code through a nice API which shouldn't take you guys long at all: you already are generating lots of code and have templates for it, I would just like to ask for easy access to those templates.
Please let me know what you think. Thanks a lot for your time.
LanceIt's something we've thought about but it's not a high enough priority right now. Certainly a feature that folks could think about implementing on their own and contributing back though. It tends to be more complicated than you'd think though
Matt -
SQL7 is 60% faster than Oracle8051EE in my test
Hi people,
I did a simple test over the weekend and want to share with
u. "SQL7 is Faster than Oracle8051 by 60% in my little test".
Perhape somebody can point out what I had not setup correctly.
one same PC installed with multi boot:
Microsoft platform
==================
NT4 Service Pack 4
SQL7
JDK1.2
JDBC from SQL7 installation
Linux Oracle Platform
=====================
RedHat linux 5.2
Oracle8051EE
jdk1.1.7A
jdbc ( oci ) from Oracle8051EE installation
I used identical Java program ( almost identical, except the
connection string) to insert 100,000 record into both platform(
one platform at a time). The table has 2 fields ( on NT name
varchar(50) and Address varchar(1024). On Oracle, is varchar2
with the same size ). No index is created in both platform. And
Linux Oracle took 32 minutes, NT SQL7 took only 13 minutes.
I were hoping that it is the different version of JDK that
contribute to the compareingly slowness in Linux Oracle.
Any one else can share some light ?
Regards
Nathan
[email protected]
nullHi,
please don'feel offended, but I think the problem with these
sort of benchmarks are:
a. It's not obvious the servers (in both cases) are optimally
tuned for the task to be done
b. The task is far too simple to state that SQL7 is 60% faster
than ORACLE 8
c. I don't know any installation where inserting 100000 rows
is the main business for the DBMS installed. Normally there's
a mix of about 85% selecting and 15% writing data (these
percentages may differ for your installation). So if you
want to test the performance of a DBMS, a bit of selecting
data wouldn't harm your benchmark
d. You did a single user benchmark (I assume). An important
issue is the behaviour of a system under multi-user load.
(NT is very strong at this point ;-)
e. The outcome of these benchmarks is irrelevant (see above)
but the psychological effect isn't ! It is the kind of
messages salesmen sprinkle around. A lot of hot air but
nothing behind it.
without wanting to be offensive, I think the correct title for
your message should have been:
I managed to configure an SQL7 and an ORACLE 8 in such way, that
an insert-job of 100000 rows is about 60% faster on the SQL7
engine. (I admit, this doesn't sound very spectacular)
Ronald
Nathan Phan (guest) wrote:
: Hi people,
: I did a simple test over the weekend and want to share with
: u. "SQL7 is Faster than Oracle8051 by 60% in my little test".
: Perhape somebody can point out what I had not setup correctly.
: one same PC installed with multi boot:
: Microsoft platform
: ==================
: NT4 Service Pack 4
: SQL7
: JDK1.2
: JDBC from SQL7 installation
: Linux Oracle Platform
: =====================
: RedHat linux 5.2
: Oracle8051EE
: jdk1.1.7A
: jdbc ( oci ) from Oracle8051EE installation
: I used identical Java program ( almost identical, except the
: connection string) to insert 100,000 record into both platform(
: one platform at a time). The table has 2 fields ( on NT name
: varchar(50) and Address varchar(1024). On Oracle, is varchar2
: with the same size ). No index is created in both platform. And
: Linux Oracle took 32 minutes, NT SQL7 took only 13 minutes.
: I were hoping that it is the different version of JDK that
: contribute to the compareingly slowness in Linux Oracle.
: Any one else can share some light ?
: Regards
: Nathan
: [email protected]
null -
I'm getting this error
java.lang.NoClassDefFoundError: com/sun/j3d/utils/applet/MainFrame
at HelloUniverse.main(Compiled Code)
I receive this error when I try to run the demos that are in the /usr/java1.1/demo folder.
I followed the directions to install java3d. I installed the java3d binary in the top part of
the JDK directory then ran the binary. Everything installed o.k., but I cannot run
any of the demos. I also have J2SE 1.2.2_05a, JDK 1.1.8_10, and.
JRE 1.1.8_10 installed. My operating system is SunOS 5.6, Solaris 2.6. My workstation
is an Ultra 5 with 374mb ram.
Here is part of the install intructions.
Place the java3d1_2-solsparc.bin file into the top level directory
of the JDK you wish to install Java 3D into. Execute the
java3d1_2-solsparc.bin file (ex: sh java3d1_2-solsparc.bin).
After installation, you may remove this file.
The Java 3D(TM) SDK includes several demo programs that can
verify correct installation. Assuming your Java 2 SDK is installed
at ~/Solaris_JDK_1.2.2_05, try the following:
cd ~/Solaris_JDK_1.2.2_05/demo/java3d/HelloUniverse
java HelloUniverse
Note: Many more demos are available under the demo/java3d/
directory. Some of the demos require a maximum memory
pool larger than the default in java. To increase the
maximum memory pool to 64 meg, add the following command
line options to java or appletviewer:
java: -mx64m
appletviewer: -J-mx64m
You do not need to include the J3D jar files in your CLASSPATH,
nor do you need to include the J3D shared libraries in your PATH.
You should include "." in your CLASSPATH or ensure that CLASSPATH
is not set.
I'm not sure how to set set/unset the CLASSPATH and I'm not sure if I was supposed to
place the binary file in the /usr/java1.1 or /usr/java or /usr/java1.2 directory.
Can anyone help?
tomjones-- If jar size isn't an issue, I recommend using thick "weblogic.jar" instead of the thin "wl*.jar" jars. The thick jar is a better performer, is used by more customers, and has more features. Otherwise:
-- It might help to use the thin client jars from a later service pack - several service packs have been released since SP2, or you might even try using jars from a recent 9.2 SP or even 10.0.
-- Also, check to see if the 1.4.2 JVM is up-to-date and/or try switching from the Sun JVM to the JRockit JVM (or vice-versa).
-- Finally, it might help to check if your XP environment matches your Linux environment (JVM command-line, classpath, etc).
-- Also: The IIOP newsgroup may also have some advice. The thin client uses the IIOP protocol even when a "t3:" URL is specified by the application.
Tom -
Sun Studio 12 is still much faster than the newest express 11/08
I gave the newest Express 11/08 a try on my laptop. I found that Studio 12 is still
much faster than the express version at least on my laptop. See the old messge below.
http://forums.sun.com/thread.jspa?threadID=5321607&tstart=15
I think poor performance is a bug for a compiler. Sun should fix it.I think poor performance is a bug for a compiler. Sun should fix it.Thanks for noting :)
This has already been filed as a bug - http://bugs.sun.com/view_bug.do?bug_id=6735472.
And as you can see it is even already fixed.
Unluckily it missed Express 11/08 integration time slot (by a mere week or so).
It is reasonable to expect it to be available at the next Express/whatever release happens next.
regards,
__Fedor. -
Vector is way faster than HashMap (why?)
I thought that HashMap would be faster than Vector (in adding stuff) ... could anyone explain to me why there was such a HUGE difference??
here's the code I used:
public class SpeedTest
public static void main(String[] args)
final int max=1000001;
Integer[] arrayzinho = new Integer[max];
Arrays.fill(arrayzinho,0,max,new Integer(1));
Vector jota = new Vector(max,max);
HashMap ele = new HashMap(max,1);
System.out.println("Adicionando " + (max-1) + " elementos ao array...");
long tempo = System.currentTimeMillis();
for(int i=0;i<max;i++)
arrayzinho[i] = new Integer(i);
System.out.println("A opera??o demorou " + ((System.currentTimeMillis()-tempo)) + " msecs.");
//ops
System.out.println("Adicionando " + (max-1) + " elementos ao Vector...");
tempo = System.currentTimeMillis();
for(int i=0;i<max;i++)
jota.add(arrayzinho);
System.out.println("A opera??o demorou " + ((System.currentTimeMillis()-tempo)) + " msecs.");
//ops
System.out.println("Adicionando " + (max-1) + " elementos ao HashMap...");
tempo = System.currentTimeMillis();
for(int i=0;i<max;i++)
ele.put(arrayzinho[i],arrayzinho[i]);
System.out.println("A opera??o demorou " + ((System.currentTimeMillis()-tempo)) + " msecs.");
Of course, when adding to HashMap, two values are entered instead of just the one added in the Vector... But, even doubling the time Vector used, the difference is huge!
here's some output I've got:
1:
Adicionando 1000000 elementos ao array...
A opera??o demorou 4500 msecs.
Adicionando 1000000 elementos ao Vector...
A opera??o demorou 469 msecs.
Adicionando 1000000 elementos ao HashMap...
A opera??o demorou 7906 msecs.
2:
Adicionando 1000000 elementos ao array...
A opera??o demorou 4485 msecs.
Adicionando 1000000 elementos ao Vector...
A opera??o demorou 484 msecs.
Adicionando 1000000 elementos ao HashMap...
A opera??o demorou 7891 msecs.
and so on, the results are almost the same everytime it's run. Does anyone know why?Note: This only times the for loop and insert into each one... not the lookup time and array stuff of the original..
Test One:
Uninitialized capacity for Vector and HashMap
import java.util.*;
public class SpeedTest
public static void main(String[] args)
final int max = 1000001;
Vector jota = new Vector(); // new Vector(max,max);
HashMap ele = new HashMap(); // new HashMap(max,1);
Integer a = new Integer(1);
long tempo = System.currentTimeMillis();
for (int i = 0; i < max; ++i)
jota.add(a);
long done = System.currentTimeMillis();
System.out.println("Vector Time " + (done - tempo) + " msecs.");
tempo = System.currentTimeMillis();
for (int i = 0; i < max; ++i)
ele.put(a, a);
done = System.currentTimeMillis();
System.out.println("Map Time " + (done-tempo) + " msecs.");
} // main
} // SpeedTestAdministrator@WACO //c
$ java SpeedTest
Vector Time 331 msecs.
Map Time 90 msecs.
Test Two:
Initialize the Vector and HashMap capacity
import java.util.*;
public class SpeedTest
public static void main(String[] args)
final int max = 1000001;
Vector jota = new Vector(max,max);
HashMap ele = new HashMap(max,1);
Integer a = new Integer(1);
long tempo = System.currentTimeMillis();
for (int i = 0; i < max; ++i)
jota.add(a);
long done = System.currentTimeMillis();
System.out.println("Vector Time " + (done - tempo) + " msecs.");
tempo = System.currentTimeMillis();
for (int i = 0; i < max; ++i)
ele.put(a, a);
done = System.currentTimeMillis();
System.out.println("Map Time " + (done-tempo) + " msecs.");
} // main
} // SpeedTestAdministrator@WACO //c
$ java SpeedTest
Vector Time 60 msecs.
Map Time 90 msecs.
We see that IF you know the capacity of the vector before its usage, it is BEST to create one of the needed capacity... -
I want to know whether JSP Runtime Environment is faster than ASP. It will be very helpfull if i get any benchmark reports. AuRevoir!
id suggest you do it yourself, no-one is going to write up this sort of stuff without you paying for it
in any case i'd dare to suggest that asp would be faster than jsp ( running on different servers no doubt; but given both windows os's ) because asp is basically vbscript which i imagine would be faster for the server to compile given a win box than jsp -> jvm -> server -> client ( if thats even how it works. ).
my opinion... -
Making code faster smaller and more elegant
hi just like yesterday I�m new to java. first of all I want to get familiar with the basics. I wrote a little game therefore. with some help. within the code are no mistakes, compiling errors or such. but now my question is why is my CPU usage nearly 75% when I run it. when the �h� ( Thread.sleep(h); ) is about 5 which makes the game faster but the CPU usage is 100%. Are there any possibilities to make the code faster? next question. are there any tricks to make the code more elegant or smaller? you know what I mean? it�s quite difficult for me to express what I want cause my English isn�t the best�
what ever here is the code
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
public class BricksGame extends JFrame implements MouseListener, MouseMotionListener{
private int mouseX, mouseY;
double a = -3;
int delta = 1;
int beta = -3;
int x_max = 288;
int y_max = 320;
int x_min = 0;
int y_min = 0;
int x = 5;
int y = 5;
int b = y_max;
int h = 15;
int y_block = 80;
int i;
int x_point;
int y_point =0;
int punkte = 0;
double k ;
double r;
int zahl = 1;
boolean changed = true;
boolean gameNotOver = true;
JPanel panelOben = new MyPanel();
JPanel panelUnten = new JPanel();
JLabel labelU1 = new JLabel();
JLabel labelU2 = new JLabel("Punktestand: 0");
JButton b1 = new JButton("restart");
public BricksGame(){
setSize(400,600);
setLocation(100,200);
Dimension full = getSize();
mouseX = full.width/2;
mouseY = full.height/2;
addMouseMotionListener(this);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {System.exit(0);}
panelOben.setLayout(null);
//Ausrichtung der Elemente
panelOben.setBounds(50, 50, 400, 500);
panelUnten.addMouseMotionListener(this);
panelUnten.setLayout(null);
//Ausrichtung der Elemente
panelUnten.setSize(300, 100);
panelUnten.setBounds(50, 500, 300, 100);
labelU1.setBounds(100,380,130,25);
labelU2.setBounds(150,430,130,25);
b1.setBounds(150,500, 80, 30);
b1.addMouseListener(this);
ImageIcon ii2 = new ImageIcon(getClass().getResource("TW1.gif"));
labelU1.setIcon(ii2);
//Hinzuf�gen der Elemente
panelUnten.add(labelU1);
panelUnten.add(labelU2);
panelUnten.add(b1);
getContentPane().add(panelOben);
getContentPane().add(panelUnten);
setResizable(false);
(new Mover()).start();
setVisible(true);
validate();
public static void main (String[]args){
BricksGame object = new BricksGame();
public void mousePressed (MouseEvent e) {}
public void mouseReleased (MouseEvent e) {}
public void mouseClicked (MouseEvent e) {
restart();
public void mouseEntered (MouseEvent e) {}
public void mouseExited (MouseEvent e) {}
public void mouseDragged (MouseEvent e) { }
public void mouseMoved (MouseEvent e) {
mouseX = e.getX();
if (mouseX <= 85){
mouseX = 85;
}else if (mouseX >= 319){
mouseX = 319;
labelU1.setBounds(mouseX -35 ,380,70,25);
* @author Haferberger
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
class Mover extends Thread{
public void run(){
while (gameNotOver){
try {Thread.sleep(h);}
catch (Exception e) {
// TODO: handle exception
repaint();
* @author Haferberger
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
class MyPanel extends JPanel{
public void paint(Graphics g){
if (y <= y_min && !changed){
// System.out.println("up");
//wie oft oben gegen
i++;
//Koordinaten des G�nen Punktes
x_point =x_max -x;
y_point =0;
//Nach 5 mal oben gegen wird der Winkel ge�ndert
if (i%5==0){
zZahl();
alpha();
//Richtungs�nderung
a = -a;
b = (int)(y_min - a*x);
changed = true;
}else if (y >= y_max && !changed){
// System.out.println("down");
//Bei Ber�hrung unten wird der Block verschoben
if (y_block == 221){
beta = -beta;
}else if (y_block == 80){
beta = -beta;
y_block+= beta;
//Betimmen wo der Ball aufkommt
if (x + 5 >= mouseX - 84 && x + 5 <= mouseX -27 ){
// System.out.println("Mitte");
}else if(x + 5 >= mouseX - 95 && x + 5 <= mouseX -85 ){
// System.out.println("au�en links");
if(delta > 0){
delta = -delta;
a = -a;
b = (int)(y_min - a*x);
}else if(x + 5 <= mouseX -16 && x + 5 >= mouseX -26 ){
// System.out.println("au�en rechts");
if(delta < 0){
delta = -delta;
a = -a;
b =(int)(y_min - a*x);
}else{
System.out.println("daneben");
gameNotOver=false;
a = -a;
b = (int)(y_max - a*x);
changed = true;
}else if (x >= x_max && !changed){
// System.out.println("right");
a = -a;
b = (int)(y - a*x_max);
delta = -delta;
changed = true;
}else if (x <= x_min && !changed){
// System.out.println("left");
a = -a;
b = (int)(y - a*x_min);
delta = -delta;
changed = true;
}else if (y == y_block && x>72 && x<216 && !changed){
// System.out.println("Balken unten");
a = -a;
b = (int)(y - a*x);
changed = true;
}else if (y == y_block+20 && x>72 && x<216 && !changed){
// System.out.println("Balken oben");
a = -a;
b = (int)(y - a*x);
changed = true;
}else{
changed = false;
g.setColor(Color.cyan);
g.fillRect(0, 0, 300, 330);
x+= delta;
y = (int)(a*x + b);
g.setColor(Color.red);
g.fillOval(x,y+5,10,10);
g.setColor(Color.magenta);
g.fillRect(72, y_block,144,20);
y_point+=2;
if(y_point==310){
y_point=500;
if(x_point + 5 >= mouseX - 94 && x_point + 5 <= mouseX -20 ){
punkte+=50;
g.setColor(Color.green);
g.fillOval(x_point,y_point,20,20);
labelU2.setText("Punktestand: " + punkte);
labelU2.validate();
public void zZahl(){
r = (Math.random() * 10);
zahl = (int)r%5 + 1;
public void alpha(){
switch(zahl){
case 4:
if (a<0){
a=-1;
}else if (a>0){
a=1;
if (delta<0){
delta=-4;
}else if (delta>0){
delta=4;
break;
case 3:
if (a<0){
a=-2;
}else if(a>0){
a=2;
if (delta<0){
delta=-4;
}else if(delta>0){
delta=4;
break;
case 5:
if (a<0){
a=-3;
}else if (a>0){
a=3;
if (delta<0){
delta=-1;
}else if (delta>0){
delta=1;
break;
case 2:
if (a<0){
a=-0.5;
}else if (a>0){
a=0.5;
if (delta<0){
delta=-4;
}else if (delta>0){
delta=4;
break;
case 1:
if (a<0){
a=-0.2;
}else if (a>0){
a=0.2;
if (delta<0){
delta=-5;
}else if (delta>0){
delta=5;
break;
public void restart(){
gameNotOver=true;
y_block=80;
beta = -3;
x=mouseX;
(new Mover()).start();
punkte = 0;
labelU2.validate();
}thanksFirst of all, big friendly advice: split your code into few classes and methods. Currently your code looks very ugly.
And one simple question: what is happening with Mover instance after restart? I don't see anything that stops old Mover thread instance before starting a new one...
And so on...
It is much simpler to answer your question when code is splited in small parts - problems then are located in small pieces of code.
Maybe you are looking for
-
Users of imovie experience a lot of problems and crying for help and no one at Apple did not respond I do not understand how a company like Apple puts experts to help users Please note that anonymous experts in Internet offer their help for money
-
Vipin: May I have your permission to connect to your computer remotely and try to solve the problem while you watch? ADOBE CUSTOMER: I need to know that NONE of my legacy adobe apps will be affected. CS5 suite and CS6 products will NOT be affected is
-
No more songs in playlists?...
all my playlists are stilled listed in itunes BUT theres no tracks in them? I recently moved tracks out of 'unknown folder' in my itunes libary but when i put them back in unknown, there was still nothing in my playlists. how can i have my playlists
-
Oracle 10g Enterprise Manager is not Running
Oracle Enterprise Manager is not running through web browser and not from command prompt. I have check all things everything is right. C:\Documents and Settings\Fizzi>cdd. 'cdd.' is not recognized as an internal or external command, operable program
-
Hi, all wat r the error handling methods in lsmw, Can any body explain.