f4b6a3 / tsid-creator

A Java library for generating Time-Sorted Unique Identifiers (TSID).
MIT License
475 stars 50 forks source link

Optimize the generation of TSID in string format #3

Closed fabiolimace closed 3 years ago

fabiolimace commented 3 years ago

Methods to optimize:

fabiolimace commented 3 years ago

Optimizations done.

Benchmark                               Mode  Cnt      Score    Error   Units
Throughput.Java_RandomBased            thrpt    5   2206,467 ± 10,305  ops/ms
Throughput.TsidCreator_Tsid256         thrpt    5  16384,145 ±  0,882  ops/ms
Throughput.TsidCreator_Tsid1024        thrpt    5   4096,236 ±  0,352  ops/ms
Throughput.TsidCreator_Tsid4096        thrpt    5   1024,061 ±  0,125  ops/ms
Throughput.TsidCreator_TsidString256   thrpt    5  11645,971 ± 99,542  ops/ms
Throughput.TsidCreator_TsidString1024  thrpt    5   4088,976 ±  0,729  ops/ms
Throughput.TsidCreator_TsidString4096  thrpt    5   1023,982 ±  0,125  ops/ms
Benchmark                               Mode  Cnt      Score    Error   Units
Throughput.JDK_RandomBased             thrpt    5   2199,582 ±  7,864  ops/ms
Throughput.TsidCreator_Tsid256         thrpt    5  16375,673 ± 38,712  ops/ms
Throughput.TsidCreator_Tsid1024        thrpt    5   4096,214 ±  0,189  ops/ms
Throughput.TsidCreator_Tsid4096        thrpt    5   1024,060 ±  0,107  ops/ms
Throughput.TsidCreator_TsidString256   thrpt    5  14806,519 ± 68,378  ops/ms <- 27% faster
Throughput.TsidCreator_TsidString1024  thrpt    5   4092,947 ±  0,909  ops/ms
Throughput.TsidCreator_TsidString4096  thrpt    5   1024,026 ±  0,135  ops/ms

Now the generation of TSID in string format is 27% faster than before.

Benchmark project: https://github.com/fabiolimace/uuid-creator-benchmark

fabiolimace commented 3 years ago

Version 2.4.0 released.