Skip to content

Commit

Permalink
store duration in instant instead of fixed decimal
Browse files Browse the repository at this point in the history
  • Loading branch information
skyz1 committed Dec 16, 2023
1 parent de41cb9 commit e9de978
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions packages/Chrono/instant.candy
Original file line number Diff line number Diff line change
@@ -1,34 +1,33 @@
[fixedDecimal, tag, check, equals, bool, ifElse] = use "Core"
[tag, check, equals, bool, ifElse] = use "Core"
constants = use "..constants"
duration = use "..duration"

## Storage Format: Instant (fixedDecimal of seconds since the Unix Epoch)
## Storage Format: Instant (Duration since the Unix Epoch)
is i := i %
Instant seconds -> fixedDecimal.is seconds
Instant dur -> duration.is dur
_ -> False

startOfUnixEpoch := Instant fixedDecimal.zero
startOfUnixEpoch := Instant duration.zero

fromUnixDuration dur :=
needs (duration.is dur)
Instant (tag.getValue dur)
Instant dur

add instant dur :=
needs (is instant)
needs (duration.is dur)
Instant (fixedDecimal.add (tag.getValue instant) (tag.getValue dur))
Instant (duration.add (tag.getValue instant) dur)
subtract instant durationOrInstant :=
needs (is instant)
needs (is durationOrInstant | bool.lazyOr { duration.is durationOrInstant })
ifElse
(is durationOrInstant)
{ duration.fromSeconds (fixedDecimal.subtract (tag.getValue instant) (tag.getValue durationOrInstant)) }
{ Instant (fixedDecimal.subtract (tag.getValue instant) (tag.getValue durationOrInstant)) }
durationOrInstant %
Instant dur -> duration.subtract (tag.getValue instant) dur
dur -> Instant (duration.subtract (tag.getValue instant) dur)

compareTo valueA valueB :=
needs (is valueA)
needs (is valueB)
result = (tag.getValue valueA) | fixedDecimal.compareTo (tag.getValue valueB)
result = (tag.getValue valueA) | duration.compareTo (tag.getValue valueB)
check (equals result Equal | bool.implies (equals valueA valueB))
result
isLessThan valueA valueB :=
Expand Down

1 comment on commit e9de978

@jwbot
Copy link
Collaborator

@jwbot jwbot commented on e9de978 Dec 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Compiler

Benchmark suite Current: e9de978 Previous: cfce928 Ratio
Time: Compiler/hello_world 17294829 ns/iter (± 335845) 17961100 ns/iter (± 843634) 0.96
Time: Compiler/fibonacci 138168473 ns/iter (± 607490) 138559255 ns/iter (± 1150242) 1.00
Time: VM Runtime/hello_world 32776 ns/iter (± 2099) 35942 ns/iter (± 58185) 0.91

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.