Skip to content

Commit f830d69

Browse files
committed
Update README.md
1 parent 9225be6 commit f830d69

11 files changed

Lines changed: 192 additions & 38 deletions

File tree

README.md

Lines changed: 61 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,18 @@
22

33
[![Maven Central](https://img.shields.io/maven-central/v/io.github.honhimw/uuid-java.svg)](https://central.sonatype.com/artifact/io.github.honhimw/uuid-java)
44

5-
## Usage
6-
75
```groovy
86
implementation 'io.github.honhimw:uuid-java:{latest}'
97
```
108

11-
```java
12-
import io.github.honhimw.uuid.*;
13-
import io.github.honhimw.uuid.gen.*;
9+
---
1410

15-
void main() {
16-
// Using via global shared instances.
17-
Generator generator = UUIDs
18-
.FAST // FAST | SECURE default configuration
19-
.V7; // V1 | V3 | V4 | V5 | V6 | V7
20-
UUID uuid = generator.next(); // Generation
11+
## Benchmark
2112

22-
// Customize generator
23-
V7 v7 = new V7(Context.builder()
24-
.clock(
25-
new V7.ClockSequenceV7() // Reseeding timestamp context
26-
.withAdditionalPrecision() // Add 12-bits for timestamp-precision
27-
)
28-
.random(() -> ThreadLocalRandom.current()) // For fast. `new SecureRandom()` for secure
29-
.node(() -> MacAddress.nodeId()) // Using other by specificizing NodeId.of(new byte[] {1, 2, 3, 4, 5, 6})
30-
.messageDigest(algorithm -> MessageDigest.getInstance(algorithm)) // MessageDigest provider(getting from thread-local cache?)
31-
.build());
32-
}
13+
```shell
14+
./gradlew bench
3315
```
3416

35-
## Benchmark
36-
3717
<details>
3818
<summary>Details</summary>
3919

@@ -69,3 +49,60 @@ void main() {
6949

7050
</details>
7151

52+
---
53+
54+
## Usage
55+
56+
```java
57+
import io.github.honhimw.uuid.*;
58+
import io.github.honhimw.uuid.gen.*;
59+
60+
void main() {
61+
// Using via global shared instances.
62+
Generator generator = UUIDs
63+
.FAST // FAST | SECURE default configuration
64+
.V7; // V1 | V3 | V4 | V5 | V6 | V7
65+
UUID uuid = generator.next(); // Generation
66+
// UUID uuid = UUIDs.FAST.V1.now(MacAddress.nodeId());
67+
// UUID uuid = UUIDs.FAST.V3.of("foo");
68+
// UUID uuid = UUIDs.FAST.V4.next();
69+
// UUID uuid = UUIDs.FAST.V5.of("bar");
70+
// UUID uuid = UUIDs.FAST.V6.now(MacAddress.nodeId());
71+
// UUID uuid = UUIDs.FAST.V7.of(Timestamp.now(CounterSequence.SHARED));
72+
}
73+
```
74+
75+
### Customize
76+
```java
77+
void main() {
78+
V7 v7 = new V7(Context.builder()
79+
.clock(
80+
new V7.ClockSequenceV7() // Reseeding timestamp context
81+
.withAdditionalPrecision() // Add 12-bits for timestamp-precision
82+
)
83+
.random(() -> ThreadLocalRandom.current()) // For fast. `new SecureRandom()` for secure
84+
.node(() -> MacAddress.nodeId()) // Using other by specificizing NodeId.of(new byte[] {1, 2, 3, 4, 5, 6})
85+
.messageDigest(algorithm -> MessageDigest.getInstance(algorithm)) // MessageDigest provider(getting from thread-local cache?)
86+
.build());
87+
v7.next(); // Generation
88+
}
89+
```
90+
91+
### Typed Uuid
92+
93+
```java
94+
import io.github.honhimw.uuid.Uuid;
95+
96+
void main() {
97+
UUID jdkUUID = UUID.randomUUID();
98+
Uuid uuid = Uuid.fromUUID(jdkUUID);
99+
100+
assert Variant.RFC4122 == uuid.variant() : "variant RFC4122";
101+
assert Version.RANDOM == uuid.version() : "version 4";
102+
assert uuid.timestamp().isEmpty() : "not time based";
103+
assert uuid.node().isEmpty() : "no node";
104+
105+
jdkUUID = uuid.asUUID();
106+
byte[] bytes = uuid.asBytes();
107+
}
108+
```

src/main/java/io/github/honhimw/uuid/gen/V7.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
/// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
2222
/// | rand_b |
2323
/// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
24-
/// ```
24+
///```
2525
///
2626
/// - unix_ts_ms: 48-bit big-endian unsigned number of the Unix Epoch timestamp in milliseconds as per Section 6.1. Occupies bits 0 through 47 (octets 0-5).
2727
/// - ver: The 4-bit version field as defined by Section 4.2, set to 0b0111 (7). Occupies bits 48 through 51 of octet 6.

src/test/java/bench/BenchmarkRunner.java

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,21 @@ public class BenchmarkRunner {
2121

2222
private static final List<RunResult> RESULTS = new ArrayList<>();
2323

24+
private static int threads;
25+
2426
@SneakyThrows
2527
public static void main(String[] args) {
28+
threads = Runtime.getRuntime().availableProcessors();
2629
v1();
2730
v3();
2831
v4();
2932
v5();
3033
v6();
3134
v7();
3235
printResult();
36+
// RESULTS.clear();
37+
// secure();
38+
// printResult();
3339
}
3440

3541
public static void printResult() {
@@ -60,7 +66,7 @@ public static void v1() {
6066
.include(V1Self.class.getSimpleName())
6167
.include(V1UuidCreator.class.getSimpleName())
6268
.include(V1Fasterxml.class.getSimpleName())
63-
.threads(6)
69+
.threads(threads)
6470
.forks(1)
6571
.build();
6672

@@ -74,7 +80,7 @@ public static void v3() {
7480
.include(V3Self.class.getSimpleName())
7581
.include(V3UuidCreator.class.getSimpleName())
7682
.include(V3Fasterxml.class.getSimpleName())
77-
.threads(6)
83+
.threads(threads)
7884
.forks(1)
7985
.build();
8086

@@ -89,7 +95,7 @@ public static void v4() {
8995
.include(V4UuidCreator.class.getSimpleName())
9096
.include(V4Fasterxml.class.getSimpleName())
9197
.include(V4Jdk.class.getSimpleName())
92-
.threads(6)
98+
.threads(threads)
9399
.forks(1)
94100
.build();
95101

@@ -103,7 +109,7 @@ public static void v5() {
103109
.include(V5Self.class.getSimpleName())
104110
.include(V5UuidCreator.class.getSimpleName())
105111
.include(V5Fasterxml.class.getSimpleName())
106-
.threads(6)
112+
.threads(threads)
107113
.forks(1)
108114
.build();
109115

@@ -117,7 +123,7 @@ public static void v6() {
117123
.include(V6Self.class.getSimpleName())
118124
.include(V6UuidCreator.class.getSimpleName())
119125
.include(V6Fasterxml.class.getSimpleName())
120-
.threads(6)
126+
.threads(threads)
121127
.forks(1)
122128
.build();
123129

@@ -132,7 +138,24 @@ public static void v7() {
132138
.include(V7Self.class.getSimpleName())
133139
.include(V7UuidCreator.class.getSimpleName())
134140
.include(V7Fasterxml.class.getSimpleName())
135-
.threads(6)
141+
.threads(threads)
142+
.forks(1)
143+
.build();
144+
145+
Collection<RunResult> run = new Runner(options).run();
146+
RESULTS.addAll(run);
147+
}
148+
149+
@SneakyThrows
150+
public static void secure() {
151+
Options options = new OptionsBuilder()
152+
.include(V1SelfSecure.class.getSimpleName())
153+
.include(V3SelfSecure.class.getSimpleName())
154+
.include(V4SelfSecure.class.getSimpleName())
155+
.include(V5SelfSecure.class.getSimpleName())
156+
.include(V6SelfSecure.class.getSimpleName())
157+
.include(V7SelfSecure.class.getSimpleName())
158+
.threads(threads)
136159
.forks(1)
137160
.build();
138161

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package bench.target;
2+
3+
import bench.AbstractBench;
4+
import io.github.honhimw.uuid.UUIDs;
5+
6+
/// @author honhimW
7+
/// @since 2025-12-10
8+
public class V1SelfSecure extends AbstractBench {
9+
10+
@Override
11+
public void run() throws Exception {
12+
UUIDs.SECURE.V1.next();
13+
}
14+
15+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package bench.target;
2+
3+
import bench.AbstractBench;
4+
import bench.Fixtures;
5+
import io.github.honhimw.uuid.UUIDs;
6+
7+
/// @author honhimW
8+
/// @since 2025-12-10
9+
public class V3SelfSecure extends AbstractBench {
10+
11+
@Override
12+
public void run() throws Exception {
13+
UUIDs.SECURE.V3.of(Fixtures.NAME);
14+
}
15+
16+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package bench.target;
2+
3+
import bench.AbstractBench;
4+
import io.github.honhimw.uuid.UUIDs;
5+
6+
/// @author honhimW
7+
/// @since 2025-12-10
8+
public class V4SelfSecure extends AbstractBench {
9+
10+
@Override
11+
public void run() throws Exception {
12+
UUIDs.SECURE.V4.next();
13+
}
14+
15+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package bench.target;
2+
3+
import bench.AbstractBench;
4+
import bench.Fixtures;
5+
import io.github.honhimw.uuid.UUIDs;
6+
7+
/// @author honhimW
8+
/// @since 2025-12-10
9+
public class V5SelfSecure extends AbstractBench {
10+
11+
@Override
12+
public void run() throws Exception {
13+
UUIDs.SECURE.V5.of(Fixtures.NAME);
14+
}
15+
16+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package bench.target;
2+
3+
import bench.AbstractBench;
4+
import io.github.honhimw.uuid.UUIDs;
5+
6+
/// @author honhimW
7+
/// @since 2025-12-10
8+
public class V6SelfSecure extends AbstractBench {
9+
10+
@Override
11+
public void run() throws Exception {
12+
UUIDs.SECURE.V6.next();
13+
}
14+
15+
}

src/test/java/bench/target/V7Self.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,14 @@
22

33
import bench.AbstractBench;
44
import io.github.honhimw.uuid.UUIDs;
5-
import io.github.honhimw.uuid.gen.V7;
65

76
/// @author honhimW
87
/// @since 2025-12-10
98
public class V7Self extends AbstractBench {
109

11-
static final V7 V7 = UUIDs.FAST.V7;
12-
1310
@Override
1411
public void run() throws Exception {
15-
V7.next();
12+
UUIDs.FAST.V7.next();
1613
}
1714

1815
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package bench.target;
2+
3+
import bench.AbstractBench;
4+
import io.github.honhimw.uuid.UUIDs;
5+
6+
/// @author honhimW
7+
/// @since 2025-12-10
8+
public class V7SelfSecure extends AbstractBench {
9+
10+
@Override
11+
public void run() throws Exception {
12+
UUIDs.SECURE.V7.next();
13+
}
14+
15+
}

0 commit comments

Comments
 (0)