| Author |
Returning object and returning integer
|
Venkata Pavan Kumar vemuri
Greenhorn
Joined: Feb 01, 2010
Posts: 14
|
|
Can anyone please tell me the answer for the scenario below
Method1: Returns an integer
Method2: Returns an object
Why does the method returning objects take more time for execution. Can anyone please explain this concept.
Thanks in Advance
Pavan.
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56192
|
|
|
Who says it takes more time?
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Venkata Pavan Kumar vemuri
Greenhorn
Joined: Feb 01, 2010
Posts: 14
|
|
It definitely takes more time because Stax parser has two implementations one cursor and second iterator
both have the same architecture only difference is that cursor uses a method which returns integers and iterator uses a method which returns objects when we calculate the parsing time of both the parsers cursors take less time this is how I inferred that there is a time difference between these two methods
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56192
|
|
|
Do you really think that your first question captures the complexity of the situation that you described in your most recent reply? And do you really think that the difference in the algorithms comes down to merely whether primitives or objects are returned?
|
 |
Venkata Pavan Kumar vemuri
Greenhorn
Joined: Feb 01, 2010
Posts: 14
|
|
I already posted the second question and nobody gave a proper answer so I did more research on this issue and narrowed it down to the first part of my question
Coming to the second question yes both are the implementations of the same API STAX which means that the only difference is wht I mentioned in the second question
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16692
|
|
Sorry, but the argument makes no sense. The only way to test it is to do nothing different than the thing that you are testing. It doesn't matter if both are based on the same algorithm -- implementation is different.
Heck, even if one does nothing but creates an object to return, and the other just creates an integer to return, it is invalid -- as you can't tell if the difference is creating the object vs creating the integer, or returning the object vs returning an integer.
Henry
|
Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
|
 |
Ireneusz Kordal
Ranch Hand
Joined: Jun 21, 2008
Posts: 423
|
|
Venkata Pavan Kumar vemuri wrote:It definitely takes more time
I run this simple test:
On my computer a difference between these two times is less than 1%,
so one can say that is no difference.
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16692
|
|
Ireneusz Kordal wrote:On my computer a difference between these two times is less than 1%,
so one can say that is no difference.
I also recommend putting it in an infinite loop -- constantly running the two tests. You may also need to throw away the first few minutes of runs, in order to allow the JIT compiler to warm up. Or else, you will be measuring the time for the interpreter and / or compiling the classes.
Henry
|
 |
 |
|
|
subject: Returning object and returning integer
|
|
|