Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #24913
| From | Eric Sosman <esosman@comcast-dot-net.invalid> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Cost of creating objects? |
| Date | 2013-08-07 08:08 -0400 |
| Organization | A noiseless patient Spider |
| Message-ID | <kttdbl$nnb$1@dont-email.me> (permalink) |
| References | <ktstsp$59k$1@news.albasani.net> <phi9da-p0l.ln1@tempest.fredriksson.dy.fi> <ktt63o$l57$1@news.albasani.net> |
On 8/7/2013 6:05 AM, Sebastian wrote:
> Am 07.08.2013 12:02, schrieb Donkey Hottie:
>> 07.08.2013 10:44, Sebastian kirjoitti:
>>> @Override
>>> public int compare(AttrValue o1, AttrValue o2)
>>> {
>>> Long ts1 = o1.getEffectiveSequenceNumber(); // ??
>>> Long ts2 = o2.getEffectiveSequenceNumber(); // ??
>>> return ts1.compareTo(ts2);
>>> }
>>>
>>> Would you expect a measureable impact of creating these
>>> variables ts1, ts2, instead of "inlining" the calls to
>>> getEffectiveSequenceNumber(). (Using JDK 6?)
>>>
>>> How can I reason about this things, probably influenced by
>>> JIT, without doing actually measurements, say as part of a
>>> code inspection?
>>>
>>> -- Sebastian
>>>
>>
>> What is getEffectiveSequenceNumber() returning?
>>
>> If Long, there is no way to prevent the creation of a Long.
>>
>> If long, try and use long variables instead, and manually code the
>> comparison code, it's not that complicated anyway.
>>
>
> Thanks for the hint, yes, I forgot to state that the method returns a
> long primitive.
>
> However, your answer does not address my question, which wasn't about
> how to code a long comparison.
He answered part of your question, essentially saying "Don't
create a Long if the returned long suits your purpose." If you
can stick with long (which it seems you can), you can eliminate
the creation and eventual collection of two Long objects. (But
if getEffectiveSequenceNumber() does four hash table lookups,
three regex matches, two Fourier transforms, and a database
query, ... Even a hundred Long's would be "in the noise.")
Primitive local variables are free, pretty nearly, but if
you move to 1.7 you could even get rid of those:
@Override
public int compare(AttrValue o1, AttrValue o2)
{
return Long.compare( // New in 1.7
o1.getEffectiveSequenceNumber(),
o2.getEffectiveSequenceNumber());
}
Of course, the named primitives that disappear from your method
may reappear as the named parameters of compare(), so it might
just be a wash. I'd imagine that any difference would be so small
as to be very difficult to measure.
--
Eric Sosman
esosman@comcast-dot-net.invalid
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Cost of creating objects? Sebastian <news@seyweiler.dyndns.org> - 2013-08-07 09:44 +0200
Re: Cost of creating objects? Donkey Hottie <donkey@fredriksson.dy.fi> - 2013-08-07 13:02 +0300
Re: Cost of creating objects? Sebastian <news@seyweiler.dyndns.org> - 2013-08-07 12:05 +0200
Re: Cost of creating objects? Donkey Hottie <donkey@fredriksson.dy.fi> - 2013-08-07 14:08 +0300
Re: Cost of creating objects? Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-08-07 08:08 -0400
Re: Cost of creating objects? Kevin McMurtrie <mcmurtrie@pixelmemory.us> - 2013-08-07 20:14 -0700
Re: Cost of creating objects? Arved Sandstrom <asandstrom2@eastlink.ca> - 2013-08-08 17:17 -0300
Re: Cost of creating objects? Joerg Meier <joergmmeier@arcor.de> - 2013-08-07 12:37 +0200
Re: Cost of creating objects? Sebastian <news@seyweiler.dyndns.org> - 2013-08-07 19:51 +0200
Re: Cost of creating objects? Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-08-07 15:51 -0400
Re: Cost of creating objects? Lew <lewbloch@gmail.com> - 2013-08-07 16:52 -0700
Re: Cost of creating objects? Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-08-07 20:51 -0400
Re: Cost of creating objects? Jukka Lahtinen <jtfjdehf@hotmail.com.invalid> - 2013-08-08 11:24 +0300
Re: Cost of creating objects? lipska the kat <"nospam at neversurrender dot co dot uk"> - 2013-08-08 10:07 +0100
Re: Cost of creating objects? Jukka Lahtinen <jtfjdehf@hotmail.com.invalid> - 2013-08-08 17:34 +0300
Re: Cost of creating objects? Arne Vajhøj <arne@vajhoej.dk> - 2013-08-08 10:42 -0400
Re: Cost of creating objects? lipska the kat <"nospam at neversurrender dot co dot uk"> - 2013-08-08 20:45 +0100
Re: Cost of creating objects? Arne Vajhøj <arne@vajhoej.dk> - 2013-08-08 10:38 -0400
Re: Cost of creating objects? Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-08-08 10:13 -0400
Re: Cost of creating objects? Arne Vajhøj <arne@vajhoej.dk> - 2013-08-07 20:28 -0400
Re: Cost of creating objects? Arved Sandstrom <asandstrom2@eastlink.ca> - 2013-08-08 17:34 -0300
Re: Cost of creating objects? lipska the kat <"nospam at neversurrender dot co dot uk"> - 2013-08-07 19:19 +0100
Re: Cost of creating objects? lipska the kat <"nospam at neversurrender dot co dot uk"> - 2013-08-07 19:24 +0100
Re: Cost of creating objects? Kevin McMurtrie <mcmurtrie@pixelmemory.us> - 2013-08-07 20:03 -0700
Re: Cost of creating objects? Arved Sandstrom <asandstrom2@eastlink.ca> - 2013-08-08 17:39 -0300
Re: Cost of creating objects? Arne Vajhøj <arne@vajhoej.dk> - 2013-08-07 20:24 -0400
csiph-web