Hi,

You may find this is due to the JIT compiler used in the Hot Spot JVM. I don't have a 
very good understanding of this area but
this is my quess as to what is happening.

loop 1: VM interprates byte code 'as is'
loops 2: VM realises the loop is a 'hot spot' so executes the loop using native code

This is a super simple explanation of these issues. As a general rule you should be 
very cautious of such a simple performance
test. You should always let the VM 'warm up' before you take the numbers. This lets 
the VM do all its internal optimisations.
This may be why your final 2 loops produce consistant results.
You should also be careful with how you write your tests. The compiler may also 
optimise your code such that a useless bit of
code you have put inside a loop may never get executed if the compiler can determine 
for sure that this code has no effect.

Cheers,

Brad

> ���¿�\(Sengwoo Oh\) wrote:
>
> Hi,
>
> I wanted to test Java3D Vector operation, but I found the strange thing in my code.
>
> In following code, the first part is the same as the second part, so 'for''s 
>computing time would be the same as the second
> 'for''s.
>
> but the result is different as following.
>
> I don't know why.
>
>  ok
> test 0's duration : 3968.0
> test 1's duration : 1782.0
> test 0's duration : 3937.0
> test 1's duration : 1750.0
>  ok
> test 0's duration : 1734.0
> test 1's duration : 1735.0
> test 0's duration : 1812.0
> test 1's duration : 1719.0
>
> //////////////////
>
> public void Test0()
>     {
>         double d0,d1;
>         double t0,t1,t2;
>         float a;
>
>         // test defined variable
>         Vector3f v0 = new Vector3f(1.0f,2.0f,3.0f);
>         Vector3f v1 = new Vector3f(3.0f,2.0f,1.0f);
>         float[] f0 = new float[3];
>         float[] f1 = new float[3];
>
>         f0[0] = 1.0f; f0[1] = 2.0f; f0[2] = 3.0f;
>         f1[0] = 3.0f; f1[1] = 2.0f; f1[2] = 1.0f;
>
>         //
>         int j;
>         long i;
>
>         System.out.println(" ok ");
>         for(j=0;j<2;j++)
>         {
>             t0 = System.currentTimeMillis();
>             // first test
>             for(i=0;i<100000000;i++)
>             {
>                 a = v0.dot(v1);
>             }
>             //
>             t1 = System.currentTimeMillis();
>             // second test
>             for(i=0;i<100000000;i++)
>             {
>                 a = v0.dot(v1);
>             }
>             //
>             t2 = System.currentTimeMillis();
>
>             System.out.println("test 0's duration : "+ (t1-t0));
>             System.out.println("test 1's duration : "+ (t2-t1));
>         } // for j
>
>         System.out.println(" ok ");
>
>         for(j=0;j<2;j++)
>         {
>             t0 = System.currentTimeMillis();
>             // first test
>             for(i=0;i<100000000;i++)
>             {
>                 a = v0.dot(v1);
>             }
>             //
>             t1 = System.currentTimeMillis();
>             // second test
>             for(i=0;i<100000000;i++)
>             {
>                 a = v0.dot(v1);
>             }
>             //
>             t2 = System.currentTimeMillis();
>
>             System.out.println("test 0's duration : "+ (t1-t0));
>             System.out.println("test 1's duration : "+ (t2-t1));
>         } // for j
>     }


----------------------------------------------------------------------------
This Email may contain confidential and/or privileged information and is
intended solely for the addressee(s) named. If you have received this
information in error, or are advised that you have been posted this Email by
accident, please notify the sender by return Email, do not redistribute it,
delete the Email and keep no copies.
----------------------------------------------------------------------------

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA3D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to