• Post Reply Bookmark Topic Watch Topic
  • New Topic

Returning object and returning integer  RSS feed

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Author and ninkuma
Marshal
Posts: 66307
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Who says it takes more time?
 
Venkata Pavan Kumar vemuri
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 66307
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
 
Ranch Hand
Posts: 423
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!