f4b6a3/uuid-creator

Optimize uuid codecs more

fabiolimace opened this issue · 2 comments

Optimize uuid codecs more

Speed increase for decoding:

  • Base16Codec: 3.5x
  • Base32Codec: 8.9x
  • Base64Codec: 8.5x
  • Base36Coced: 8.7x
  • Base58Codec: 8.4x
  • Base62Codec: 8.2x
  • StringCodec: 1.5x

Speed increase for encoding:

  • Base16Codec: 1.4x
  • Base32Codec: 1.4x
  • Base64Codec: 1.5x
  • Base36Coced: 4.0x
  • Base58Codec: 4.9x
  • Base62Codec: 4.7x
  • StringCodec: 1.0x

Speed compared to JDK 8:

  • StringCodec.decode(): 7x faster than UUID.fromString()
  • StringCodec.encode(): 7x faster than UUID.toString()
  • Base16Codec.encode(): 22x faster than UUID.toString().replaceAll("-")

BEFORE OPTIMIZATION (v3.7.0):

------------------------------------------------------------------
Benchmark                  Mode  Cnt      Score     Error   Units
------------------------------------------------------------------
Throughput.decode_base16  thrpt    5   4695,920 ±   6,835  ops/ms
Throughput.decode_base32  thrpt    5   2146,940 ±  26,668  ops/ms
Throughput.decode_base64  thrpt    5   2566,964 ±  25,757  ops/ms
Throughput.decode_base36  thrpt    5    528,938 ±   3,441  ops/ms *
Throughput.decode_base58  thrpt    5    609,171 ±   8,800  ops/ms *
Throughput.decode_base62  thrpt    5    629,332 ±   2,297  ops/ms *
------------------------------------------------------------------
Throughput.encode_base16  thrpt    5  18432,630 ± 171,769  ops/ms
Throughput.encode_base32  thrpt    5  20345,201 ± 126,980  ops/ms
Throughput.encode_base64  thrpt    5  21841,282 ±  43,678  ops/ms
Throughput.encode_base36  thrpt    5    267,618 ±  22,657  ops/ms *
Throughput.encode_base58  thrpt    5    243,444 ±  20,533  ops/ms *
Throughput.encode_base62  thrpt    5    257,363 ±  14,720  ops/ms *
------------------------------------------------------------------

AFTER OPTIMIZATION (v3.7.1):

------------------------------------------------------------------
 Benchmark                  Mode  Cnt      Score     Error   Units
------------------------------------------------------------------
Throughput.decode_base16  thrpt    5  16278,459 ± 535,333  ops/ms
Throughput.decode_base32  thrpt    5  19190,166 ± 163,644  ops/ms
Throughput.decode_base64  thrpt    5  21783,804 ± 191,067  ops/ms
Throughput.decode_base36  thrpt    5   4598,355 ±  60,168  ops/ms *
Throughput.decode_base58  thrpt    5   5125,792 ±  64,979  ops/ms *
Throughput.decode_base62  thrpt    5   5157,235 ±  40,137  ops/ms *
------------------------------------------------------------------
Throughput.encode_base16  thrpt    5  26206,302 ± 305,194  ops/ms
Throughput.encode_base32  thrpt    5  28777,567 ± 344,404  ops/ms
Throughput.encode_base64  thrpt    5  31791,024 ± 579,749  ops/ms
Throughput.encode_base36  thrpt    5   1077,678 ±   9,852  ops/ms *
Throughput.encode_base58  thrpt    5   1201,396 ±  25,900  ops/ms *
Throughput.encode_base62  thrpt    5   1218,330 ±  14,767  ops/ms *
------------------------------------------------------------------

Test coverage: 90.0%

Version 3.7.1 released.