diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d27b67..f6288c8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ All notable changes to this project will be documented in this file. Nothing unreleased. +## [5.1.0] - 2022-10-22 + +Add a fast method to generate identifiers. #22 + ## [5.0.2] - 2022-09-17 Rewrite docs. #21 @@ -298,8 +302,9 @@ Project created as an alternative Java implementation of [ULID spec](https://git - Added `LICENSE` - Added test cases -[unreleased]: https://github.com/f4b6a3/ulid-creator/compare/ulid-creator-5.0.2...HEAD -[5.0.2]: https://github.com/f4b6a3/ulid-creator/compare/ulid-creator-5.0.0...ulid-creator-5.0.2 +[unreleased]: https://github.com/f4b6a3/ulid-creator/compare/ulid-creator-5.1.0...HEAD +[5.0.2]: https://github.com/f4b6a3/ulid-creator/compare/ulid-creator-5.0.2...ulid-creator-5.1.0 +[5.0.2]: https://github.com/f4b6a3/ulid-creator/compare/ulid-creator-5.0.1...ulid-creator-5.0.2 [5.0.1]: https://github.com/f4b6a3/ulid-creator/compare/ulid-creator-5.0.0...ulid-creator-5.0.1 [5.0.0]: https://github.com/f4b6a3/ulid-creator/compare/ulid-creator-4.2.1...ulid-creator-5.0.0 [4.2.1]: https://github.com/f4b6a3/ulid-creator/compare/ulid-creator-4.2.0...ulid-creator-4.2.1 diff --git a/README.md b/README.md index 9a187ec..e45b87e 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ Add these lines to your `pom.xml`. com.github.f4b6a3 ulid-creator - 5.0.2 + 5.1.0 ``` See more options in [maven.org](https://search.maven.org/artifact/com.github.f4b6a3/ulid-creator). @@ -125,6 +125,14 @@ Sequence of Monotonic ULIDs: ### More Examples +Create a quick ULID: + +```java +Ulid ulid = Ulid.fast(); +``` + +--- + Create a ULID from a canonical string (26 chars): ```java @@ -253,16 +261,19 @@ This section shows benchmarks comparing `UlidCreator` to `UUID.randomUUID()`. -------------------------------------------------------------------------------- THROUGHPUT (operations/msec) Mode Cnt Score Error Units -------------------------------------------------------------------------------- -UUID_randomUUID thrpt 5 3459,889 ± 98,257 ops/ms +UUID_randomUUID thrpt 5 3459,889 ± 98,257 ops/ms (1.00) UUID_randomUUID_toString thrpt 5 3148,298 ± 159,507 ops/ms - - - - - - - - - - - - - - - - - - - - - - - - - - - -UlidCreator_getUlid thrpt 5 4276,614 ± 11,069 ops/ms +Ulid_fast thrpt 5 34523,147 ± 1022,114 ops/ms (9.98) +Ulid_fast_toString thrpt 5 19161,375 ± 662,563 ops/ms +- - - - - - - - - - - - - - - - - - - - - - - - - - - +UlidCreator_getUlid thrpt 5 4276,614 ± 11,069 ops/ms (1.23) UlidCreator_getUlid_toString thrpt 5 3645,088 ± 85,478 ops/ms - - - - - - - - - - - - - - - - - - - - - - - - - - - -UlidCreator_getMonotonicUlid thrpt 5 32921,698 ± 1286,983 ops/ms +UlidCreator_getMonotonicUlid thrpt 5 32921,698 ± 1286,983 ops/ms (9.51) UlidCreator_getMonotonicUlid_toString thrpt 5 18541,252 ± 710,281 ops/ms -------------------------------------------------------------------------------- -Total time: 00:02:01 +Total time: 00:02:41 -------------------------------------------------------------------------------- ``` diff --git a/benchmark/src/main/java/benchmark/Throughput.java b/benchmark/src/main/java/benchmark/Throughput.java index 3588c07..b29566d 100644 --- a/benchmark/src/main/java/benchmark/Throughput.java +++ b/benchmark/src/main/java/benchmark/Throughput.java @@ -37,6 +37,16 @@ public class Throughput { return UUID.randomUUID().toString(); } + @Benchmark + public Ulid Ulid_fast() { + return Ulid.fast(); + } + + @Benchmark + public String Ulid_fast_toString() { + return Ulid.fast().toString(); + } + @Benchmark public Ulid UlidCreator_getUlid() { return UlidCreator.getUlid(); @@ -46,7 +56,7 @@ public class Throughput { public String UlidCreator_getUlid_toString() { return UlidCreator.getUlid().toString(); } - + @Benchmark public Ulid UlidCreator_getMonotonicUlid() { return UlidCreator.getMonotonicUlid(); diff --git a/src/main/java/com/github/f4b6a3/ulid/Ulid.java b/src/main/java/com/github/f4b6a3/ulid/Ulid.java index c9a3eea..e9ecc2b 100644 --- a/src/main/java/com/github/f4b6a3/ulid/Ulid.java +++ b/src/main/java/com/github/f4b6a3/ulid/Ulid.java @@ -26,12 +26,13 @@ package com.github.f4b6a3.ulid; import java.io.Serializable; import java.time.Instant; +import java.util.SplittableRandom; import java.util.UUID; /** * A class that represents ULIDs. *

- * ULID is 128-bit value that has two components: + * ULID is a 128-bit value that has two components: *