This is the mail archive of the java@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: java.util.Date.toString() really slow?


On Sun, Jun 02, 2002 at 10:20:39PM -0700, Adam Megacz wrote:
> 
> The following code takes 1:35 using 3.1-branch and 0:02 with
> HotSpot. Any ideas why?
> 
>   - a
> 
> import java.util.*;
> public class test {
>     public static void main(String[] s) throws Exception {
>         for(int i=0; i<200; i++) System.out.println(new Date());
>     }
> }

It is java.util.Timezone that is the problem.
Not only is it dead slow, it also reports *wrong* timezone
in most cases. 
I have earlier posted a one-line patch that fixes both problems 
on my Debian system. This is the result with your program
on my machine (J2SDK and gcj from CVS with the patch):

----- J2SDK -----------------------------------------------------
bash-2.05a$ java -version
java version "1.3.1"
Java(TM) 2 Runtime Environment, Standard Edition (build Blackdown-1.3.1-FCS)
Java HotSpot(TM) Client VM (build Blackdown-1.3.1-FCS, mixed mode)

bash-2.05a$ time java test >/dev/null 

real	0m1.772s
user	0m1.270s
sys	0m0.230s

----- GCJ -----------------------------------------------------

bash-2.05a$ /usr/local/gcc-3.2/bin/gcj -v
Reading specs from /usr/local/gcc-3.2/lib/gcc-lib/i586-pc-linux-gnu/3.2/specs
Reading specs from /usr/local/gcc-3.2/lib/gcc-lib/i586-pc-linux-gnu/3.2/../../../libgcj.spec
rename spec lib to liborig
Configured with: ./configure --prefix=/usr/local/gcc --enable-languages=c++,java --disable-static --enable-threads --enable-java-awt=xlib,gtk : (reconfigured)  : (reconfigured)  : (reconfigured)  : (reconfigured) ./configure --prefix=/usr/local/gcc-3.2 --enable-languages=c++,java --disable-static --enable-threads --enable-java-awt=xlib,gtk : (reconfigured)  : (reconfigured)  : (reconfigured)  : (reconfigured) 
Thread model: posix
gcc version 3.2 20020602 (experimental)

bash-2.05a$ time ./test >/dev/null 

real	0m0.914s
user	0m0.860s
sys	0m0.050s

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

Much better, thank you.
I don't know if the patch works on other systems,
but java.util.TimeZone clearly needs a rewrite.

regards,
--
Göran


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]