Hello,

     I was unable to get the date/time information consistently.

Exe 1.3:
**********************************************************************
Date d1 = new Date();
for (int i=0; i<10000000; i++) { int j = i;}

        Date d2 = new Date();

        long elapsed_time = d2.getTime() - d1.getTime();
        System.out.println("That took " + elapsed_time
                + " milliseconds");
    }
**********************************************************************
I will normally get d2.getTime() - d1.getTime() = 0
But if I ran it again, it will be able to get the time different.

Exe 3.1
********************************************************************************************
import java.io.*;
        class SystemDemo {
           public static void main(String args[]) throws IOException {
                int arr1[] = new int[1050000];
                int arr2[] = new int[1050000];
                long startTime, endTime;
        /* initialize arr1 */
                for (int i = 0; i < arr1.length; i++) {
                arr1[i] = i + 1;
                }

        /* copying manually */
        startTime = System.currentTimeMillis();
        System.out.println("start time: " + startTime + " ms.");
        for (int i = 0; i < arr1.length; i++) {
        arr2[i] = arr1[i];
          }
        endTime = System.currentTimeMillis();
        System.out.println("end time: " + endTime + " ms.");
        System.out.println("Time for manual copy: " + (endTime-startTime) + "
ms.");

        /* using the copy utility provided by java */
        startTime = System.currentTimeMillis();
        System.out.println("start time: " + startTime + " ms.");
        System.arraycopy(arr1, 0, arr2, 0, arr1.length);
        endTime = System.currentTimeMillis();
        System.out.println("end time: " + endTime + " ms.");
        System.out.println("Time when using method of array copy: " +
(endTime-startTime) + " ms.");
        System.gc(); //force garbage collector to work
        //System.setIn(new FileInputStream("temp.txt"));
        System.exit(0);

        }

}
***********************************************************************************************************
Sometime I get Time for manual copy and array copy = 0ms;
But I can only get the manual copy time = 15ms but array copy time
still 0ms after few run.
If i try to debug the code by inserting a System.out.println
(startTime), I might get the result the other way around.
which is manual copy time = 0ms and array copy time = 15ms.

Pls help... I'm not sure what is causing this strange behavior.

BestRegards,
YH

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to javaprogrammingwithpassion@googlegroups.com
To unsubscribe from this group, send email to 
javaprogrammingwithpassion-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/javaprogrammingwithpassion?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to