Re: Function call overhead

Ken Gentle <[email protected]> Fri, 7 Dec 2007 08:29:00 -0500
Newsgroups gmane.comp.windows.devel.java.advanced
Message-ID <[email protected]>
Hopefully this is a typo, but "byte[] buff" in MyClass isn't allocated
anything other than a zero-length array, and it appears that the
MyClass(byte[] bytes) constructor is missing as well.

Hard to say without all the pieces...  ;-)

Ken

On 12/7/07, Avinash Lakshman <[email protected]> wrote:
>
> I am seeing this wierd problem. When I do the following I see the time
> taken is around 170 ms.
>
> public static void main(String[] args) throws Throwable
>     {
>         Random random = new Random();
>         byte[] bytes = new byte[64*1024*1024];
>         random.nextBytes(bytes);
>
>         int pos = 0;
>         int count = bytes.length;
>         long start2 = System.currentTimeMillis();
>         while ( true )
>         {
>             int value = (pos < count) ? (bytes[pos] & 0xff) : -1;
>             ++pos;
>             if ( value == -1 )
>                 break;
>         }
>         System.out.println("TIME TAKEN : " + (System.currentTimeMillis() -
> start2));
> }
>
> Now I do the following I see the time taken is 516 ms:
>
> class MyClass
> {
>     private byte[] buf = new byte[0];
>     private int pos;
>     private int count;
>
>     public final int read()
>         {
>             if (pos < count)
>             {
>                 return ( buf[pos++] & 0xFF );
>             }
>             else
>                 return -1;
>         }
> }
>
> public void main(String[] args)
> {
>      MyClass myClass = new MyClass(bytes);
>         int read = 0;
>         long start = System.currentTimeMillis();
>         while ( true )
>         {
>             read = myClass.read();
>             if ( read == -1 )
>                 break;
>         }
>         System.out.println("TIME TAKEN : " + (System.currentTimeMillis() -
> start));
> }
>
> What is going on?
>
> Thanks
> A
>
> _________________________________________________________________
> Your smile counts. The more smiles you share, the more we donate. Join in.
> www.windowslive.com/smile?ocid=TXT_TAGLM_Wave2_oprsmilewlhmtagline
> ===================================
> This list is hosted by DevelopMentor(R)  http://www.develop.com
>
> View archives and manage your subscription(s) at
> http://discuss.develop.com
>



--
J. Kenneth Gentle (Ken)
Gentle Software LLC
Phone: 484.371.8137
Mobile: 302.547.7151
Email:  [email protected]
Email:  [email protected]
www.gentlesoftware.com

===================================
This list is hosted by DevelopMentor®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com