EasyUtcNow v1.0.0

Crystal lang module -- Faster and easier way to get an utc timestamp than calling standard Time lib

A timestamp module

Faster and easier way to get an utc timestamp than calling standard Time lib

Installation :

Add this to your application's shard.yml:

dependencies:
  easy_utc_now:
    github: ndudnicz/EasyUtcNow
    version: 1.0.0

Example :

require "easy_utc_now"

puts EasyUtcNow.now_utc_to_unix

API :

Static Methods Summary :

.now_utc_to_unix :
Int64

        Returns the current utc epoch timestamp in second

.now_utc_to_unix_ms_f :
Float64

        Returns the current utc epoch timestamp in msecond

.now_utc_to_unix_f :
Float64

        Returns the current utc epoch timestamp in second as Float64

Benchmark :

$> crystal -v
Crystal 1.13.1 (2024-07-12)

LLVM: 18.1.8
Default target: aarch64-apple-darwin23.5.0
$> cd bench
$> crystal build --release bench.cr
$> ./bench
             Time.utc.to_unix  71.93M ( 13.90ns) (± 1.53%)  0.0B/op   1.15× slower
   EasyUtcNow.now_utc_to_unix  82.46M ( 12.13ns) (± 3.96%)  0.0B/op        fastest
          Time.utc.to_unix_ms  58.34M ( 17.14ns) (± 2.67%)  0.0B/op   1.41× slower
EasyUtcNow.now_utc_to_unix_ms  82.19M ( 12.17ns) (± 1.26%)  0.0B/op        fastest
           Time.utc.to_unix_f  72.33M ( 13.83ns) (± 1.05%)  0.0B/op   1.15× slower
 EasyUtcNow.now_utc_to_unix_f  83.02M ( 12.05ns) (± 1.16%)  0.0B/op        fastest
Repository

EasyUtcNow

Owner
Statistic
  • 3
  • 0
  • 0
  • 0
  • 0
  • 4 months ago
  • March 28, 2019
License

MIT License

Links
Synced at

Thu, 21 Nov 2024 17:35:03 GMT

Languages