The results of my benchmark shows that the performance is worst when the branch has 15% (or 85%) percent probability rather than 50%.
Any explanation?
The code is too long but the relevant parts are here:
private int diff(char c) {
return TABLE[(145538857 * c) >>> 27] - c;
}
@Benchmark int timeBranching(int reps) {
int result = 0;
while (reps-->0) {
for (final char c : queries) {
if (diff(c) == 0) {
++result;
}
}
}
return result;
}
It counts the number of BREAKING_WHITESPACE characters in the given string. The results shows a sudden time drop (performance increase) when the branching probability reaches about 0.20.
More details about the drop. Varying the seed shows more strange things happening. Note that the black line denoting the minimum and maximum values is very short except when close to the cliff.
java.util.Random
(which should be good enough for this). And also with the prescribed number of matching chars, see the linked code. – Alternation0
as a seed. I wonder if the distribution of values it is creating is favorable to the cases with0.20
,0.50
, and0.80
. Have you tested it with justnew Random()
and without the0
seed? – Obycom.google.caliper.BeforeExperiment
. – Obynew Random()
and see what happens and not track the seed at all. Each new invocation ofRandom()
will give you a new generator that is unlikely to be similar to the previous one. Internally the constructor will create a seed. – Oby