f4b6a3 / uuid-creator

UUID Creator is a Java library for generating Universally Unique Identifiers.
MIT License
430 stars 44 forks source link

Optimize UuidComparator #71

Closed fabiolimace closed 2 years ago

fabiolimace commented 2 years ago

Benchmark results before the changes:

Benchmark            Mode  Cnt       Score      Error   Units
Throughput.compare  thrpt    5   88384,168 ± 4418,918  ops/ms

Benchmark results after the changes:

Benchmark            Mode  Cnt       Score      Error   Units
Throughput.compare  thrpt    5  262282,968 ±  483,948  ops/ms (2.967528)

Benchmark code:


package benchmark;

import java.util.UUID;
import java.util.concurrent.TimeUnit;

import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Fork;
import org.openjdk.jmh.annotations.Measurement;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.OutputTimeUnit;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.Threads;
import org.openjdk.jmh.annotations.Warmup;

import com.github.f4b6a3.uuid.UuidCreator;
import com.github.f4b6a3.uuid.util.UuidComparator;

@Fork(1)
@Threads(1)
@State(Scope.Benchmark)
@Warmup(iterations = 5, time = 1)
@Measurement(iterations = 5, time = 3)
@BenchmarkMode(Mode.Throughput)
@OutputTimeUnit(TimeUnit.MILLISECONDS)
public class Throughput {

    UUID uuid1 = new UUID(0L, 0L);
    UUID uuid2 = new UUID(0L, 0L);

    @Benchmark
    public int compare() {
        return UuidComparator.opaqueCompare(uuid1, uuid2);
    }
}
fabiolimace commented 2 years ago

Released v5.1.1