xerial / scala-ulid

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

scala-ulid

CI Scala Steward badge Maven Central Scaladoc License

scala-ulid is a library for ULID.

Installation

Add the following to your sbt build (2.11.x, 2.12.x, 2.13.x):

val version = "..."

libraryDependencies += Seq(
  "com.chatwork" %% "scala-ulid" % version
)

Usage

val ulid = ULID.generate()
val str = ulid.asString
println(str) // 01EQWGKT1S68Y9YM5TV34RQVQA
ULID.parseULID(str).foreach{ uild =>
  println(ulid) // 01EQWGKT1S68Y9YM5TV34RQVQA
}

val bytes = uild.toBytes
ULID.fromBytes(bytes).foreach { ulid =>
  println(ulid) // 01EQWGKT1S68Y9YM5TV34RQVQA
}

Benchmark

https://github.com/chatwork/scala-ulid/blob/main/benchmark/src/main/scala/jmh/ULIDBenchmark.scala

-airframe/airframe-controlsulky/sulky-ulidchatwork/scala-ulid
Random number generationCalling Random#nextDouble 16 timesCalling Random#nextLong twice (upper 48 bits useless random number generation)Calling Random#nextBytes(10) only once
Latency 95%tile(nsec)1038
(newULIDString=1024nsec)
524460
Latency Max(msec)1.329
(newULIDString=0.755msec)
0.7210.790
  • java.util.UUID#randomUUID is 95%tile = 327nsec, max = 0.703msec

About

License:MIT License


Languages

Language:Scala 96.7%Language:Shell 3.3%