Regarding Exercise number 3.1,
Go into code line under Your startTime = System.currentTimeMillis();
type sout then hit tab and pass startTime to Println method,
Do the same for endTime
and check, if the time is the same.
If yes, Add more data
Pacior
> 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 [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/javaprogrammingwithpassion?hl=en
-~----------~----~----~----~------~----~------~--~---