String a = "aa";

the String object "a" is not created
that goes into the literal pool of the class ...

btw
array.length is a property not a method

probably array.length also doesn't do any calculation.

still I'm not convinced with my reasoning,
can anyone else help us out.


----- Original Message -----
From: "Panagiotis Konstantinidis" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, December 14, 2001 6:04 AM
Subject: Re: OffBeat question...Java performance.


>   Hmmm.. Using jdk1.4 under windows 2000 I got the error message:
>
> not a statement: String a = "aa";
>
>   Declarign a String a; and changing the String a = "aa"; to a += "aa"; it
worked but, despite my predictions, the first chunk of code run faster than
the second! I would expect the second to be faster... After running the
program twice doing a
> += "aa", the first loop yielded 45396 and 45075 respectively while the
second loop yeilded 46486 and 45255.
>
>   Weird. Since the first loop has the overhead of recalculating the arary
length (even if it is a minimum overhead calculation) I would expect
different results...
>
> 14/12/2001 10:58:23, ShriKant Vashishtha <[EMAIL PROTECTED]>
wrote:
>
> >Hi,
> >
> >This is the actual code which I tested. I am using the IBM WebSphere3.53
> >JIT
> >enabled compiler. In my view also the second code should have been
faster.
> >But
> >it's the first code instead which is puzzling me.
> >
> >-ShriKant
> >
> >
> >
> >A mailing list about Java Server Pages specification and reference wrote:
> >
> >> From: Sujit <[EMAIL PROTECTED]>@JAVA.SUN.COM on 12/14/2001 05:35 AM
EST
> >>
> >> Please respond to A mailing list about Java Server Pages specification
> >and
> >>       reference <[EMAIL PROTECTED]>
> >>
> >> To:   [EMAIL PROTECTED]
> >> cc:
> >> Subject:  Re: OffBeat question...Java performance.
> >>
> >> Is this the actual code you tested and got the output ...
> >> or
> >> instead of the line String a = "aa";
> >> you had some other code ??
> >>
> >> actually, String a = "aa"; even if you loop does nothing ...
> >>
> >> I think both the for loop will not be executed at all ...
> >>
> >> the JVM should optimises the code ...
> >> and the time should be same ...
> >>
> >> BTW your second code snippet should be faster than the first one ...
> >>
> >> ----- Original Message -----
> >> From: "ShriKant Vashishtha" <[EMAIL PROTECTED]>
> >> To: <[EMAIL PROTECTED]>
> >> Sent: Friday, December 14, 2001 5:14 AM
> >> Subject: Re: OffBeat question...Java performance.
> >>
> >> > Hi,
> >> >
> >> > I apologise for the mistake. You are right. Please find the currect
> >> > snippets.
> >> >
> >> >         String [] arrayStr = new String[20000];
> >> >         System.out.println(System.currentTimeMillis());
> >> >         for(i=0;i<arrayStr.length;i++){
> >> >                     String a="aa";
> >> >         }
> >> >         System.out.println(System.currentTimeMillis());
> >> >
> >> > Output:
> >> > 1008319728796
> >> > 1008319728799
> >> >
> >> >         String [] arrayStr = new String[20000];
> >> >         int length = arrayStr.length;
> >> >         System.out.println(System.currentTimeMillis());
> >> >         for(i=0;i<length;i++){
> >> >             String a="aa";
> >> >         }
> >> >         System.out.println(System.currentTimeMillis());
> >> >
> >> > Output:
> >> > 1008319767200
> >> > 1008319767221
> >> >
> >> > Regards,
> >> > -ShriKant
> >> >
> >> > A mailing list about Java Server Pages specification and reference
> >wrote:
> >> >
> >> > > From: Sujit <[EMAIL PROTECTED]>@JAVA.SUN.COM on 12/14/2001 04:51
AM
> >> EST
> >> > >
> >> > > Please respond to A mailing list about Java Server Pages
> >specification
> >> > and
> >> > >       reference <[EMAIL PROTECTED]>
> >> > >
> >> > > To:   [EMAIL PROTECTED]
> >> > > cc:
> >> > > Subject:  Re: OffBeat question...Java performance.
> >> > >
> >> > > what is the difference between both the code ..
> >> > >
> >> > > I don't see any difference between the code
> >> > > that is embedded between the system.out's
> >> > >
> >> > > am I missing something ??
> >> > >
> >> > > ----- Original Message -----
> >> > > From: "ShriKant Vashishtha" <[EMAIL PROTECTED]>
> >> > > To: <[EMAIL PROTECTED]>
> >> > > Sent: Friday, December 14, 2001 4:34 AM
> >> > > Subject: OffBeat question...Java performance.
> >> > >
> >> > > > Hi,
> >> > > >
> >> > > > I am trying to judge the performance impact of the following Java
> >> code.
> >> > > >
> >> > > >         String [] arrayStr = new String[20000];
> >> > > >         System.out.println(System.currentTimeMillis());
> >> > > >         for(i=0;i<arrayStr.length;i++){
> >> > > >                     String a="aa";
> >> > > >         }
> >> > > >         System.out.println(System.currentTimeMillis());
> >> > > >
> >> > > > Output:
> >> > > > 1008319728796
> >> > > > 1008319728799
> >> > > >
> >> > > >         String [] arrayStr = new String[20000];
> >> > > >         int length = arrayStr.length;
> >> > > >         System.out.println(System.currentTimeMillis());
> >> > > >         for(i=0;i<arrayStr.length;i++){
> >> > > >             String a="aa";
> >> > > >         }
> >> > > >         System.out.println(System.currentTimeMillis());
> >> > > >
> >> > > > Output:
> >> > > > 1008319767200
> >> > > > 1008319767221
> >> > > >
> >> > > > In my view the first code stub should have been faster as in the
> >> second
> >> > > > snippet we are getting an overhead of a instance variable call
over
> >> an
> >> > > > String [] object compared to the length already computed in the
> >first
> >> > > > one. What is happening behind the scene, I am not aware. Could
> >> somebody
> >> > > > please explain.
> >> > > >
> >> > > > Thanks,
> >> > > > -ShriKant
> >> > > >
> >> > > >
> >> > >
> >> >
> >>
>
>===========================================================================
> >> > > > To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
> >> > > JSP-INTEREST".
> >> > > > For digest: mailto [EMAIL PROTECTED] with body: "set
> >JSP-INTEREST
> >> > > DIGEST".
> >> > > > Some relevant FAQs on JSP/Servlets can be found at:
> >> > > >
> >> > > >  http://archives.java.sun.com/jsp-interest.html
> >> > > >  http://java.sun.com/products/jsp/faq.html
> >> > > >  http://www.esperanto.org.nz/jsp/jspfaq.jsp
> >> > > >  http://www.jguru.com/faq/index.jsp
> >> > > >  http://www.jspinsider.com
> >> > > >
> >> > >
> >> > >
> >> >
> >>
>
>===========================================================================
> >> > > To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
> >> > > JSP-INTEREST".
> >> > > For digest: mailto [EMAIL PROTECTED] with body: "set
JSP-INTEREST
> >> > > DIGEST".
> >> > > Some relevant FAQs on JSP/Servlets can be found at:
> >> > >
> >> > >  http://archives.java.sun.com/jsp-interest.html
> >> > >  http://java.sun.com/products/jsp/faq.html
> >> > >  http://www.esperanto.org.nz/jsp/jspfaq.jsp
> >> > >  http://www.jguru.com/faq/index.jsp
> >> > >  http://www.jspinsider.com
> >> >
> >> >
> >>
>
>===========================================================================
> >> > To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
> >> JSP-INTEREST".
> >> > For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST
> >> DIGEST".
> >> > Some relevant FAQs on JSP/Servlets can be found at:
> >> >
> >> >  http://archives.java.sun.com/jsp-interest.html
> >> >  http://java.sun.com/products/jsp/faq.html
> >> >  http://www.esperanto.org.nz/jsp/jspfaq.jsp
> >> >  http://www.jguru.com/faq/index.jsp
> >> >  http://www.jspinsider.com
> >> >
> >>
> >>
>
>===========================================================================
> >> To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
> >> JSP-INTEREST".
> >> For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST
> >> DIGEST".
> >> Some relevant FAQs on JSP/Servlets can be found at:
> >>
> >>  http://archives.java.sun.com/jsp-interest.html
> >>  http://java.sun.com/products/jsp/faq.html
> >>  http://www.esperanto.org.nz/jsp/jspfaq.jsp
> >>  http://www.jguru.com/faq/index.jsp
> >>  http://www.jspinsider.com
> >
>
>===========================================================================
> >To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
JSP-INTEREST".
> >For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST
DIGEST".
> >Some relevant FAQs on JSP/Servlets can be found at:
> >
> > http://archives.java.sun.com/jsp-interest.html
> > http://java.sun.com/products/jsp/faq.html
> > http://www.esperanto.org.nz/jsp/jspfaq.jsp
> > http://www.jguru.com/faq/index.jsp
> > http://www.jspinsider.com
> >
> __________________________________________
> "It can only be attributed to human error"
> 2001 A Space Odyssey
>
>
===========================================================================
> To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
JSP-INTEREST".
> For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST
DIGEST".
> Some relevant FAQs on JSP/Servlets can be found at:
>
>  http://archives.java.sun.com/jsp-interest.html
>  http://java.sun.com/products/jsp/faq.html
>  http://www.esperanto.org.nz/jsp/jspfaq.jsp
>  http://www.jguru.com/faq/index.jsp
>  http://www.jspinsider.com
>

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://archives.java.sun.com/jsp-interest.html
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.jsp
 http://www.jguru.com/faq/index.jsp
 http://www.jspinsider.com

Reply via email to