Skip to content

Repository files navigation

UUID Generator

Maven Central

implementation 'io.github.honhimw:uuid-java:{latest}'

Benchmark

./gradlew bench
Details

JMH version: 1.37
VM version: JDK 25.0.1, Java HotSpot (TM) 64-Bit Server VM, 25.0.1+8-LTS-jvmci-b01
Warmup: 2 iterations, 1 s each
Measurement: 4 iterations, 1 s each
Threads: 6 threads, will synchronize iterations
Benchmark mode: Throughput, ops/time

NameScore(thrpt)
V1Fasterxml9889.128 ops/ms
V1Self248979.250 ops/ms
V1SelfSecure23203.039 ops/ms
V1UuidCreator34402.695 ops/ms
V3Fasterxml6918.611 ops/ms
V3Self56499.424 ops/ms
V3SelfSecure54563.924 ops/ms
V3UuidCreator41852.958 ops/ms
V4Fasterxml3081285.846 ops/ms
V4Jdk1021.013 ops/ms
V4Self3040052.353 ops/ms
V4SelfSecure251.294 ops/ms
V4UuidCreator44051.426 ops/ms
V5Fasterxml3327.681 ops/ms
V5Self27256.804 ops/ms
V5SelfSecure27326.388 ops/ms
V5UuidCreator23258.985 ops/ms
V6Fasterxml9896.053 ops/ms
V6Self274965.694 ops/ms
V6SelfSecure23408.190 ops/ms
V6UuidCreator35989.205 ops/ms
V7Fasterxml31870.053 ops/ms
V7Fastest1292723.959 ops/ms
V7Self1404916.850 ops/ms
V7SelfSecure297.321 ops/ms
V7UuidCreator19100.390 ops/ms

Usage

importio.github.honhimw.uuid.*;
importio.github.honhimw.uuid.gen.*;
voidmain() {
// Using via global shared instances.Generatorgenerator = UUIDs
.FAST// FAST | SECURE default configuration
.V7; // V1 | V3 | V4 | V5 | V6 | V7UUIDuuid = generator.next(); // Generation// UUID uuid = UUIDs.FAST.V1.now(MacAddress.nodeId());// UUID uuid = UUIDs.FAST.V3.of("foo");// UUID uuid = UUIDs.FAST.V4.next();// UUID uuid = UUIDs.FAST.V5.of("bar");// UUID uuid = UUIDs.FAST.V6.now(MacAddress.nodeId());// UUID uuid = UUIDs.FAST.V7.of(CounterSequence.SHARED.timestamp());
}

Customize

voidmain() {
V7v7 = newV7(Context.builder()
.clock(
newV7.ClockSequenceV7() // Reseeding timestamp context
.withAdditionalPrecision() // Add 12-bits for timestamp-precision
)
.random(() -> ThreadLocalRandom.current()) // For fast. `new SecureRandom()` for secure
.node(() -> MacAddress.nodeId()) // Using other by specificizing NodeId.of(new byte[] {1, 2, 3, 4, 5, 6})
.messageDigest(algorithm -> MessageDigest.getInstance(algorithm)) // MessageDigest provider(getting from thread-local cache?)
.build());
v7.next(); // Generation
}

Typed Uuid

importio.github.honhimw.uuid.Uuid;
voidmain() {
UUIDjdkUUID = UUID.randomUUID();
Uuiduuid = Uuid.fromUUID(jdkUUID);
assertVariant.RFC4122 == uuid.variant() : "variant RFC4122";
assertVersion.RANDOM == uuid.version() : "version 4";
assertuuid.timestamp().isEmpty() : "not time based";
assertuuid.node().isEmpty() : "no node";
jdkUUID = uuid.asUUID();
byte[] bytes = uuid.asBytes();
} 

About

Light-weight, Full-features(rfc9562), Extensible, JRE8+ UUID generators for V1, V3, V4, V5, V6, V7(optional timestamp addition precision).

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages