gfc-time
![Coverage Status](https://camo.githubusercontent.com/2f10d47f10cc1d8472eac9b218fa4441c44b351e09baf8844847dcb7b0128f31/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6766632d636f6c6c6563746976652f6766632d74696d652f62616467652e7376673f6272616e63683d6d617374657226736572766963653d676974687562)
A library that contains time related scala utility classes. A fork and new home of the now unmaintained Gilt Foundation Classes (com.gilt.gfc
), now called the GFC Collective, maintained by some of the original authors.
Getting gfc-time
The latest version is 1.0.0, released on 21/Jan/2020 and cross-built against Scala 2.12.x and 2.13.x.
If you're using SBT, add the following line to your build file:
libraryDependencies += "org.gfccollective" %% "gfc-time" % "1.0.0"
For Maven and other build tools, you can visit search.maven.org. (This search will also list other available libraries from the GFC Collective.)
Contents and Example Usage
org.gfccollective.time.Timer
Various utilities for timing & reporting on blocks of code and scala Futures.
-
Format a nanosecond timespan into a human-readable string, like "37 us" or "45 days 08:55:01".
val start = System.nanoTime() doSomething() val elapsed = Timer.pretty(System.nanoTime() - start) println(s"doSomething() took $elapsed")
-
Report ns result (Long value)
val result = Timer.time(l => println(s"Operation took $l ns")) { // timed function, returning a result }
-
Report formatted result. The result String is using the best suitable time unit (e.g. "10 ns", "456 ms", "45 days 08:55:01" etc.)
val result = Timer.time(s => println(s"Operation took ${s}")) { // timed function, returning a result }
-
Time the body, then calls pretty on the elapsed time to get a more human-friendly time String, then passes that to the "format" method.
val result = Timer.time("Operation took %s", println _)) { // timed function, returning a result }
-
Similar functions as above are available to time scala Future completions.
org.gfccollective.time.Timestamp
A immutable lightweight wrapper around a millisecond timestamp.
License
Licensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0