Re: Improving String.equals() implementation
- From: Eric Sosman <Eric.Sosman@xxxxxxx>
- Date: Tue, 07 Oct 2008 12:07:19 -0400
Lew wrote:
Eric Sosman wrote:/** A trivial class with a "safe" equals() method */
private static class Safe {
private final int value;
private Safe(int value) {
this.value = value;
}
public boolean equals(Object obj) {
return (obj instanceof Safe) && (value == ((Safe)obj).value);
}
}
/** A trivial class with a "fast" equals() method. */
private static class Fast {
private final int value;
private Fast(int value) {
this.value = value;
}
public boolean equals(Object obj) {
return (value == ((Fast)obj).value);
}
}
}
I think I caught the obvious gotchas.
The behaviors of the two 'equals()' implementations are not
equivalent.
A fair benchmark would compare methods with the same behaviors.
I don't understand your objection. The methods are different
because the point of the exercise was to measure the performance
impact of their difference, as a follow-up to Lothar Kimmeringer's
point about the cost of a "redundant" instanceof test. If both
methods had (or both lacked) the test, what would be measured?
--
Eric.Sosman@xxxxxxx
.
- Follow-Ups:
- References:
- Improving String.equals() implementation
- From: softwarepearls_com
- Re: Improving String.equals() implementation
- From: Lew
- Re: Improving String.equals() implementation
- From: John W Kennedy
- Re: Improving String.equals() implementation
- From: Mark Space
- Re: Improving String.equals() implementation
- From: Eric Sosman
- Re: Improving String.equals() implementation
- From: Mark Space
- Re: Improving String.equals() implementation
- From: Tom Anderson
- Re: Improving String.equals() implementation
- From: Lothar Kimmeringer
- Re: Improving String.equals() implementation
- From: Eric Sosman
- Re: Improving String.equals() implementation
- From: Tom Anderson
- Re: Improving String.equals() implementation
- From: Eric Sosman
- Re: Improving String.equals() implementation
- From: Lew
- Improving String.equals() implementation
- Prev by Date: Training & jobs
- Next by Date: Re: Storing data periodically on remote server
- Previous by thread: Re: Improving String.equals() implementation
- Next by thread: Re: Improving String.equals() implementation
- Index(es):
Relevant Pages
|