Closed dmurat closed 2 years ago
I like it.
I will replace System.currentTimeMillis()
with SystemClock.millis()
. They have the same performance in benchmarks.
All JDK versions from 8 to 14 have the same implementation for the method SystemClock.millis()
as follows:
@Override
public long millis() {
return System.currentTimeMillis();
}
List of SystemClock.millis()
implementations:
Now the COMB factories have constructors with a Clock
parameter for tests.
public final class PrefixCombFactory extends AbstRandomBasedFactory {
public PrefixCombFactory(Clock clock) {
this(new DefaultRandomFunction(), clock);
}
public PrefixCombFactory(Random random, Clock clock) {
this(getRandomFunction(random), clock);
}
public PrefixCombFactory(RandomFunction randomFunction, Clock clock) {
super(UuidVersion.VERSION_RANDOM_BASED, randomFunction);
this.clock = clock;
}
The performance before and after the change is the same.
BEFORE:
Benchmark Mode Cnt Score Error Units
UuidCreator_PrefixComb thrpt 5 2704,653 ± 53,146 ops/ms
UuidCreator_ShortPrefixComb thrpt 5 2091,576 ± 51,236 ops/ms
AFTER:
Benchmark Mode Cnt Score Error Units
UuidCreator_PrefixComb thrpt 5 2745,823 ± 53,917 ops/ms
UuidCreator_ShortPrefixComb thrpt 5 2116,982 ± 27,708 ops/ms
Also added clock parameters to DefaultTimeFunction
and WindowsTimeFunction
for tests. The performance is the same too.
Released version v4.4.1.
Thank you, sir. You are very kind and fast :-)
For easier testing with generated UUIDs, it would be great to have
getShortPrefixComb
,getPrefixComb
,getShortSuffixComb
andgetSuffixComb
variants that acceptjava.time.Clock
parameter. Tnx.