easy_utc_now

Version, currently 0.1.03 versions

github.com/ndudnicz/EasyUtcNow

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

3 stars
0 dependents
License: MIT

Nothing has been indexed for 0.1.0 yet. The tag is recorded, its shard.yml has not been read, so the manifest and dependency list below are empty because they are unknown rather than because they are absent.

Installation

# Add this to your shard.yml
dependencies:
  easy_utc_now:
    github: ndudnicz/EasyUtcNow
    version: ~> 0.1.0

Then run:

shards install

shard.yml

No shard.yml has been indexed for 0.1.0. You can read it on the repository.

Dependencies

Unknown: the shard.yml for this version has not been read yet.

README

This README is the one indexed from the repository at its latest ref, not from the tag for this version.

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