|
|
Subject:
Compare time needed to pass array
Category: Computers > Programming Asked by: jcoen-ga List Price: $10.50 |
Posted:
31 Jul 2005 11:08 PDT
Expires: 30 Aug 2005 11:08 PDT Question ID: 550086 |
I need some kind of timer object to compare the ammount of time required to pass a large array by value, vs. by reference. In the Main method, two methods, one expecting it to be passed by value, the other by reference, should be called with the timer object running on each one, as when everything is done executing, it should output the ammount of time it took to pass the large array by value and the ammount of time it took to pass it by reference. | |
| |
|
|
There is no answer at this time. |
|
Subject:
Re: Compare time needed to pass array
From: efn-ga on 31 Jul 2005 16:16 PDT |
I suggest you specify the operating system under which the test program is to run and the programming language with which you wish to test. |
Subject:
Re: Compare time needed to pass array
From: efn-ga on 31 Jul 2005 23:40 PDT |
Java doesn't give you two different ways to pass an array to a function. All you can do is pass a reference to an array. That means that the array is not copied and the called function can modify it. I suppose if you wanted to simulate passing an array by value, you could make a copy of the array and pass a reference to the copy, but if you did that, the difference would only be in the calling function. The interface to the called function would be the same in both cases. You might be interested in these discussions: http://www.yoda.arachsys.com/java/passing.html http://www.jguru.com/faq/view.jsp?EID=430996 |
Subject:
Re: Compare time needed to pass array
From: rhansenne-ga on 01 Aug 2005 03:38 PDT |
A quick and dirty way to quickly time some code in Java: long startTime = System.currentTimeMillis(); // execute code here... long endTime = System.currentTimeMillis(); System.out.println("Duration: "+(endTime - startTime)+"ms"); |
Subject:
Re: Compare time needed to pass array
From: sucker5-ga on 01 Aug 2005 09:07 PDT |
efn was correct, in java and many other true oo lang's you always pass by "reference". But if you are using something like c++ you can do either. If you pass a pointer or by reference you are just passing the address of the array. If you pass the entire array, a copy is made so you have O(n) time assuming it is an actual array and not another data structure. It depends on ,n, the number of elements in the array. |
Subject:
Re: Compare time needed to pass array
From: edheal-ga on 02 Aug 2005 03:38 PDT |
To get an more accurate measurment for timing you need to repeat the passing by value/reference many times and take the average. This removed inconsistencies due to the operating system performing other tasks. In addition ensure that you have no other programs running. |
Subject:
Re: Compare time needed to pass array
From: flaviusmaximus-ga on 10 Aug 2005 11:57 PDT |
sorry to butt in. I can't provide code at this time. Additionally, as was pointed out your specific environment may affect results. That said, my experience has been pretty consistent. I have real life example using ORACLE and PL/SQL arrays and Cobol program. At the time, PL/SQL ARRAYS were pass by value only. When converted to Cobol using pass by reference, we learned that 90% of the cost of the process was overhead of copying arrays. This is an actual real worl app stat, not an estimate. FYI, today pl/sql support and "NOCOPY" parameter which passes by reference. So, this may not be your environment, and your milage may vary but in general if the arrays are big enough, then an order of magnitude is not out of the questions. Good luck. Kevin |
If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you. |
Search Google Answers for |
Google Home - Answers FAQ - Terms of Service - Privacy Policy |