Which Java UUID Generator Is Fastest? JMH Benchmark Comparison

This article explains the purpose of UUIDs, common use cases, compares several Java UUID generation libraries, and presents JMH benchmark results showing that the mica implementation based on Java 9 outperforms JDK 8 ThreadLocalRandom and Hutool FastSimpleUUID by three to four times.

Java Architecture Diary
Java Architecture Diary
Java Architecture Diary
Which Java UUID Generator Is Fastest? JMH Benchmark Comparison

Introduction

UUID's purpose is to give every element in a distributed system a unique identifier without requiring a central authority.

Common UUID Use Cases

IOT devices – device IDs

Website session IDs and cookie user IDs

Database primary keys

UUID Generation Libraries

Popular Java tools include the Hutool library and the mica framework, which is based on Spring and Java 8 micro‑service utilities.

Benchmark Code

The benchmarks are built with JMH, a micro‑benchmarking suite that measures method‑level performance with microsecond precision. The source code is available on GitHub.

jdk8UUId

@Benchmark
public String jdk8UUId() {
    return UUID.randomUUID().toString();
}

jdk8ThreadLocalRandomUUId

@Benchmark
public String jdk8ThreadLocalRandomUUId() {
    ThreadLocalRandom random = ThreadLocalRandom.current();
    UUID uuid = new UUID(random.nextInt(), random.nextInt());
    return uuid.toString();
}

hutoolFastSimpleUUID

@Benchmark
public String hutoolFastSimpleUUID() {
    return IdUtil.fastSimpleUUID();
}

micaUUId

@Benchmark
public String micaUUId() {
    return StringUtil.getUUID();
}

Benchmark Environment

OS: macOS Mojave

CPU: 2.8 GHz Intel Core i5

RAM: 8 GB 1600 MHz DDR3

JVM: Oracle 1.8.0_201 64‑bit

Benchmark Results

The JMH measurements (operations per millisecond) are:

jdk8 UUID: 734.6 ops/ms

jdk8ThreadLocalRandom: 3 224.8 ops/ms

hutoolFastSimpleUUID: 3 619.7 ops/ms

mica UUID (Java 9 style): 12 375.4 ops/ms

Higher scores indicate more UUIDs generated per millisecond.

Conclusion

The mica implementation, which follows the Java 9 UUID generation algorithm, delivers performance three to four times better than both the JDK 8 ThreadLocalRandom approach and Hutool's FastSimpleUUID.

Because UUID generation often requires high throughput and concurrency, developers should consider using Java 9+ APIs or adopting the mica algorithm for optimal speed.

Open‑Source Recommendations

Open source QR code
Open source QR code

Links

hutool Java toolkit: https://gitee.com/loolly/hutool

mica Spring/Java 8 micro‑service toolkit: https://github.com/lets-mica/mica

Additional QR code
Additional QR code
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

JavaperformanceuuidBenchmarkJMH
Java Architecture Diary
Written by

Java Architecture Diary

Committed to sharing original, high‑quality technical articles; no fluff or promotional content.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.