Skip to content

Commit

Permalink
fix it to work with crystal 0.34 and release v0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ndudnicz committed Jun 7, 2020
1 parent 8897b17 commit b2f343c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ Int64
        Returns the current utc epoch timestamp in second

```ruby
.now_utc_to_unix_ms :
Int64
.now_utc_to_unix_ms_f :
Float64
```
        Returns the current utc epoch timestamp in msecond

Expand All @@ -42,17 +42,17 @@ Float64
### Benchmark :
```shell
$> crystal -v
Crystal 0.27.2 [60760a546] (2019-02-05)
Crystal 0.34.0 [4401e90f0] (2020-04-06)

LLVM: 4.0.0
LLVM: 8.0.0
Default target: x86_64-unknown-linux-gnu
$> cd bench
$> crystal build --release bench.cr
$> ./bench
Time.utc_now.to_unix 19.49M ( 51.31ns) (± 1.25%) 0 B/op 1.13× slower
Crtimestamp.now_utc_to_unix 21.98M ( 45.49ns) (± 0.72%) 0 B/op fastest
Time.utc_now.to_unix_ms 19.59M ( 51.03ns) (± 0.93%) 0 B/op 1.12× slower
Crtimestamp.now_utc_to_unix_ms 21.86M ( 45.74ns) (± 0.98%) 0 B/op fastest
Time.utc_now.to_unix_f 19.47M ( 51.36ns) (± 1.57%) 0 B/op 1.12× slower
Crtimestamp.now_utc_to_unix_f 21.88M ( 45.71ns) (± 0.95%) 0 B/op fastest
Time.utc.to_unix 31.17M ( 32.08ns) (± 0.79%) 0.0B/op 1.20× slower
Crtimestamp.now_utc_to_unix 37.30M ( 26.81ns) (± 0.15%) 0.0B/op fastest
Time.utc.to_unix_ms 27.54M ( 36.31ns) (± 0.53%) 0.0B/op 1.36× slower
Crtimestamp.now_utc_to_unix_ms 37.36M ( 26.77ns) (± 0.09%) 0.0B/op fastest
Time.utc.to_unix_f 29.93M ( 33.41ns) (± 4.18%) 0.0B/op 1.25× slower
Crtimestamp.now_utc_to_unix_f 37.33M ( 26.79ns) (± 2.33%) 0.0B/op fastest
```
8 changes: 4 additions & 4 deletions bench/bench.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ require "benchmark"
require "../src/crtimestamp"

Benchmark.ips do |x|
x.report("Time.utc_now.to_unix") { Time.utc_now.to_unix }
x.report("Time.utc.to_unix") { Time.utc.to_unix }
x.report("Crtimestamp.now_utc_to_unix") { Crtimestamp.now_utc_to_unix }
end
Benchmark.ips do |x|
x.report("Time.utc_now.to_unix_ms") { Time.utc_now.to_unix_ms }
x.report("Crtimestamp.now_utc_to_unix_ms") { Crtimestamp.now_utc_to_unix_ms }
x.report("Time.utc.to_unix_ms") { Time.utc.to_unix_ms }
x.report("Crtimestamp.now_utc_to_unix_ms") { Crtimestamp.now_utc_to_unix_ms_f }
end
Benchmark.ips do |x|
x.report("Time.utc_now.to_unix_f") { Time.utc_now.to_unix_f }
x.report("Time.utc.to_unix_f") { Time.utc.to_unix_f }
x.report("Crtimestamp.now_utc_to_unix_f") { Crtimestamp.now_utc_to_unix_f }
end
8 changes: 4 additions & 4 deletions shard.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
name: crtimestamp
version: 0.1.0
version: 0.2.0

crystal: 0.27.2
crystal: 0.34.0

authors:
- Nicolas Dudniczenko <[email protected]>
- ndudnicz <[email protected]>

description: |
Faster way to get a timestamp than calling standard Time
Faster way to get a timestamp than calling standard Time lib
license: GPL-3.0
2 changes: 1 addition & 1 deletion src/crtimestamp.cr
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ struct Crtimestamp
# ```
# Time.now_utc_to_unix_ms # => 1452567845876
# ```
def self.now_utc_to_unix_ms : Int64
def self.now_utc_to_unix_ms_f : Float64
seconds, nanoseconds = Crystal::System::Time.compute_utc_seconds_and_nanoseconds
(seconds * 1_000 + (nanoseconds / NANOSECONDS_PER_MILLISECOND)) - EPOCH_MSECONDS_TIMESTAMP
end
Expand Down

0 comments on commit b2f343c

Please sign in to comment.