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

Reply via email to