Initial Dever 0.0.1
This commit is contained in:
commit
81233d098c
1479 files changed
+163782
No files matched your search
@@ -0,0 +1,39 @@
|
||||
type InputResult {
|
||||
Parsed(value: Decimal)
|
||||
error Invalid
|
||||
}
|
||||
|
||||
type State {
|
||||
total: Decimal
|
||||
factor: Decimal
|
||||
}
|
||||
|
||||
type Sample {
|
||||
elapsed_ns: Int
|
||||
checksum: Text
|
||||
}
|
||||
|
||||
parsed(value: Decimal) (result: Decimal) { result = value }
|
||||
parsed(value: null) (result: Decimal) { fail(InputResult.Invalid) }
|
||||
|
||||
step(value: Int, state: State) (next: State) {
|
||||
next = State {
|
||||
total = state.total + decimal.fromInt(value) * state.factor
|
||||
factor = state.factor
|
||||
}
|
||||
}
|
||||
|
||||
run(ticks: Text, initial: Text, factor: Text) (sample: Sample) {
|
||||
bytes = dever.bytes.fromText(ticks)
|
||||
state = State { total = parsed(decimal.parse(initial))
|
||||
factor = parsed(decimal.parse(factor)) }
|
||||
begin = dever.time.monotonicNanos()
|
||||
final = reduce(step, bytes, state)
|
||||
end = dever.time.monotonicNanos()
|
||||
sample = Sample { elapsed_ns = end - begin
|
||||
checksum = decimal.toText(final.total) }
|
||||
}
|
||||
|
||||
continuous(ticks: Text, initial: Text, factor: Text) (samples: List<Sample>) {
|
||||
samples = [run(ticks, initial, factor), run(ticks, initial, factor), run(ticks, initial, factor), run(ticks, initial, factor), run(ticks, initial, factor), run(ticks, initial, factor), run(ticks, initial, factor), run(ticks, initial, factor), run(ticks, initial, factor), run(ticks, initial, factor)]
|
||||
}
|
||||
Reference in new issue
Block a user