411 lines
14 KiB
Plaintext
411 lines
14 KiB
Plaintext
type Sample {
|
|
elapsed_ns: Int
|
|
checksum: Int
|
|
}
|
|
|
|
type FloatSample {
|
|
elapsed_ns: Int
|
|
checksum: Float
|
|
}
|
|
|
|
type Record {
|
|
first: Int
|
|
second: Int
|
|
third: Int
|
|
}
|
|
|
|
type OwnedRecord {
|
|
name: Text
|
|
tags: List<Text>
|
|
count: Int
|
|
}
|
|
|
|
type Accumulator {
|
|
values: List<Int>
|
|
count: Int
|
|
}
|
|
|
|
type Lookup {
|
|
values: Map<Int, Int>
|
|
index: Int
|
|
total: Int
|
|
}
|
|
|
|
type TextLookup {
|
|
values: Map<Text, Int>
|
|
total: Int
|
|
}
|
|
|
|
type TextPair {
|
|
left: Text
|
|
right: Text
|
|
}
|
|
|
|
rule selected(value: Int?) (out: Int)
|
|
| value | out |
|
|
| null | 0 |
|
|
| other | value |
|
|
|
|
loop total(values: List<Int>) (out: Int)
|
|
| each value in values | result |
|
|
| out | sum value |
|
|
|
|
loop byteTotal(values: Bytes) (out: Int)
|
|
| each value in values | result |
|
|
| out | sum value |
|
|
|
|
loop floatTotal(values: Bytes) (out: Float)
|
|
| each value in values | result |
|
|
| out | sum float.fromInt(value) |
|
|
|
|
loop buildList(values: Bytes) (out: List<Int>)
|
|
| each value in values | result |
|
|
| out | list value |
|
|
|
|
loop buildMap(values: Bytes) (out: Map<Int, Int>)
|
|
| each value in values | result |
|
|
| out | fold(acc = {}, putValue(value, acc)) |
|
|
|
|
loop mapTotal(values: Map<Int, Int>) (out: Int)
|
|
| each entry in entries(values) | result |
|
|
| out | sum entry.value |
|
|
|
|
loop buildRecords(values: Bytes) (out: List<Record>)
|
|
| each value in values | result |
|
|
| out | list Record { first = value, second = 0, third = 0 } |
|
|
|
|
loop recordTotal(values: List<Record>) (out: Int)
|
|
| each row in values | result |
|
|
| out | sum row.first + row.second + row.third |
|
|
|
|
ownedRecord(value: Int) (row: OwnedRecord) {
|
|
name = "row-value-" + int.toText(value)
|
|
row = OwnedRecord { name = name, tags = [name], count = value - length(name) - 1 }
|
|
}
|
|
|
|
inspectOwned(row: OwnedRecord) (value: Int) {
|
|
value = row.count + length(row.name) + length(row.tags)
|
|
}
|
|
|
|
forwardOwned(row: OwnedRecord) (value: Int) {
|
|
value = inspectOwned(row)
|
|
}
|
|
|
|
loop ownedRecords(values: Bytes) (out: List<OwnedRecord>)
|
|
| each value in values | result |
|
|
| out | list ownedRecord(value) |
|
|
|
|
loop inspectRecords(values: List<OwnedRecord>) (out: Int)
|
|
| each row in values | result |
|
|
| out | sum forwardOwned(row) |
|
|
|
|
appendField(value: Int, state: Accumulator) (next: Accumulator) {
|
|
next = Accumulator { values = append(state.values, value), count = state.count + 1 }
|
|
}
|
|
|
|
appendInspected(value: Int, state: Accumulator) (next: Accumulator) {
|
|
count = length(state.values) + 1
|
|
next = Accumulator { values = append(state.values, value), count = count }
|
|
}
|
|
|
|
loop updateRecords(values: Bytes) (out: Accumulator)
|
|
| each value in values | result |
|
|
| out | fold(acc = Accumulator { values = [], count = 0 }, appendField(value, acc)) |
|
|
|
|
loop inspectUpdates(values: Bytes) (out: Accumulator)
|
|
| each value in values | result |
|
|
| out | fold(acc = Accumulator { values = [], count = 0 }, appendInspected(value, acc)) |
|
|
|
|
lookup(value: Int, state: Lookup) (next: Lookup) {
|
|
found = selected(get(state.values, state.index))
|
|
next = Lookup { values = state.values, index = state.index + 1, total = state.total + found }
|
|
}
|
|
|
|
loop lookupValues(input: Bytes, initial: Lookup) (out: Lookup)
|
|
| each value in input | result |
|
|
| out | fold(acc = initial, lookup(value, acc)) |
|
|
|
|
loop textEntries(values: List<MapEntry<Int, Int>>) (out: Map<Text, Int>)
|
|
| each entry in values | result |
|
|
| out | fold(acc = {}, textEntry(entry, acc)) |
|
|
|
|
loop textKeys(values: List<MapEntry<Text, Int>>) (out: List<Text>)
|
|
| each entry in values | result |
|
|
| out | list entry.key |
|
|
|
|
textLookup(key: Text, state: TextLookup) (next: TextLookup) {
|
|
found = selected(get(state.values, key))
|
|
next = TextLookup { values = state.values, total = state.total + found }
|
|
}
|
|
|
|
loop lookupText(keys: List<Text>, initial: TextLookup) (out: TextLookup)
|
|
| each key in keys | result |
|
|
| out | fold(acc = initial, textLookup(key, acc)) |
|
|
|
|
textPair(value: Int) (pair: TextPair) {
|
|
left = "compare-value-" + int.toText(value)
|
|
pair = TextPair { left = left, right = text.lower(text.upper(left)) }
|
|
}
|
|
|
|
rule matchedValue(matched: Bool) (value: Int)
|
|
| matched | value |
|
|
| true | 120 |
|
|
| false | 0 |
|
|
|
|
loop textPairs(values: Bytes) (out: List<TextPair>)
|
|
| each value in values | result |
|
|
| out | list textPair(value) |
|
|
|
|
loop equalPairs(rows: List<TextPair>) (out: Int)
|
|
| each row in rows | result |
|
|
| out | sum matchedValue(row.left == row.right) |
|
|
|
|
loop containsPairs(rows: List<TextPair>) (out: Int)
|
|
| each row in rows | result |
|
|
| out | sum matchedValue(text.contains(row.left, row.right)) |
|
|
|
|
loop joinText(chunks: List<Text>) (out: Text)
|
|
| each value in chunks | result |
|
|
| out | fold(acc = "", appendText(value, acc)) |
|
|
|
|
loop byteChunks(chunks: List<Text>) (out: List<Bytes>)
|
|
| each value in chunks | result |
|
|
| out | list dever.bytes.fromText(value) |
|
|
|
|
loop joinBytes(chunks: List<Bytes>) (out: Bytes)
|
|
| each value in chunks | result |
|
|
| out | fold(acc = dever.bytes.fromText(""), appendBytes(value, acc)) |
|
|
|
|
flow integer(ticks: Text) (sample: Sample)
|
|
| step | kind | do |
|
|
| input | calc | dever.bytes.fromText(ticks) |
|
|
| begin | flow | dever.time.monotonicNanos() |
|
|
| value | loop | byteTotal(input) |
|
|
| end | flow | dever.time.monotonicNanos() |
|
|
| sample | calc | Sample { elapsed_ns = end - begin, checksum = value } |
|
|
|
|
loop continuousInteger(ticks: Text) (samples: List<Sample>)
|
|
| each value in range(0, 10) | result |
|
|
| samples | list integer(ticks) |
|
|
|
|
flow float(ticks: Text) (sample: FloatSample)
|
|
| step | kind | do |
|
|
| input | calc | dever.bytes.fromText(ticks) |
|
|
| begin | flow | dever.time.monotonicNanos() |
|
|
| value | loop | floatTotal(input) |
|
|
| end | flow | dever.time.monotonicNanos() |
|
|
| sample | calc | FloatSample { elapsed_ns = end - begin, checksum = value } |
|
|
|
|
loop continuousFloat(ticks: Text) (samples: List<FloatSample>)
|
|
| each value in range(0, 10) | result |
|
|
| samples | list float(ticks) |
|
|
|
|
flow list(ticks: Text) (sample: Sample)
|
|
| step | kind | do |
|
|
| input | calc | dever.bytes.fromText(ticks) |
|
|
| begin | flow | dever.time.monotonicNanos() |
|
|
| values | loop | buildList(input) |
|
|
| end | flow | dever.time.monotonicNanos() |
|
|
| sample | calc | Sample { elapsed_ns = end - begin, checksum = total(values) } |
|
|
|
|
loop continuousList(ticks: Text) (samples: List<Sample>)
|
|
| each value in range(0, 10) | result |
|
|
| samples | list list(ticks) |
|
|
|
|
flow map(ticks: Text) (sample: Sample)
|
|
| step | kind | do |
|
|
| input | calc | dever.bytes.fromText(ticks) |
|
|
| begin | flow | dever.time.monotonicNanos() |
|
|
| values | loop | buildMap(input) |
|
|
| end | flow | dever.time.monotonicNanos() |
|
|
| sample | calc | Sample { elapsed_ns = end - begin, checksum = mapTotal(values) } |
|
|
|
|
loop continuousMap(ticks: Text) (samples: List<Sample>)
|
|
| each value in range(0, 10) | result |
|
|
| samples | list map(ticks) |
|
|
|
|
flow listRead(ticks: Text) (sample: Sample)
|
|
| step | kind | do |
|
|
| values | loop | buildList(dever.bytes.fromText(ticks)) |
|
|
| begin | flow | dever.time.monotonicNanos() |
|
|
| value | loop | total(values) |
|
|
| end | flow | dever.time.monotonicNanos() |
|
|
| sample | calc | Sample { elapsed_ns = end - begin, checksum = value } |
|
|
|
|
loop continuousListRead(ticks: Text) (samples: List<Sample>)
|
|
| each value in range(0, 10) | result |
|
|
| samples | list listRead(ticks) |
|
|
|
|
flow mapRead(ticks: Text) (sample: Sample)
|
|
| step | kind | do |
|
|
| values | loop | buildMap(dever.bytes.fromText(ticks)) |
|
|
| begin | flow | dever.time.monotonicNanos() |
|
|
| value | loop | mapTotal(values) |
|
|
| end | flow | dever.time.monotonicNanos() |
|
|
| sample | calc | Sample { elapsed_ns = end - begin, checksum = value } |
|
|
|
|
loop continuousMapRead(ticks: Text) (samples: List<Sample>)
|
|
| each value in range(0, 10) | result |
|
|
| samples | list mapRead(ticks) |
|
|
|
|
flow listRecord(ticks: Text) (sample: Sample)
|
|
| step | kind | do |
|
|
| input | calc | dever.bytes.fromText(ticks) |
|
|
| begin | flow | dever.time.monotonicNanos() |
|
|
| values | loop | buildRecords(input) |
|
|
| end | flow | dever.time.monotonicNanos() |
|
|
| sample | calc | Sample { elapsed_ns = end - begin, checksum = recordTotal(values) } |
|
|
|
|
loop continuousListRecord(ticks: Text) (samples: List<Sample>)
|
|
| each value in range(0, 10) | result |
|
|
| samples | list listRecord(ticks) |
|
|
|
|
flow listRecordRead(ticks: Text) (sample: Sample)
|
|
| step | kind | do |
|
|
| values | loop | buildRecords(dever.bytes.fromText(ticks)) |
|
|
| begin | flow | dever.time.monotonicNanos() |
|
|
| value | loop | recordTotal(values) |
|
|
| end | flow | dever.time.monotonicNanos() |
|
|
| sample | calc | Sample { elapsed_ns = end - begin, checksum = value } |
|
|
|
|
loop continuousListRecordRead(ticks: Text) (samples: List<Sample>)
|
|
| each value in range(0, 10) | result |
|
|
| samples | list listRecordRead(ticks) |
|
|
|
|
flow callRead(ticks: Text) (sample: Sample)
|
|
| step | kind | do |
|
|
| rows | loop | ownedRecords(dever.bytes.fromText(ticks)) |
|
|
| begin | flow | dever.time.monotonicNanos() |
|
|
| value | loop | inspectRecords(rows) |
|
|
| end | flow | dever.time.monotonicNanos() |
|
|
| sample | calc | Sample { elapsed_ns = end - begin, checksum = value + length(rows) - length(rows) } |
|
|
|
|
loop continuousCallRead(ticks: Text) (samples: List<Sample>)
|
|
| each value in range(0, 10) | result |
|
|
| samples | list callRead(ticks) |
|
|
|
|
flow recordUpdate(ticks: Text) (sample: Sample)
|
|
| step | kind | do |
|
|
| input | calc | dever.bytes.fromText(ticks) |
|
|
| begin | flow | dever.time.monotonicNanos() |
|
|
| state | loop | updateRecords(input) |
|
|
| end | flow | dever.time.monotonicNanos() |
|
|
| sample | calc | Sample {
|
|
elapsed_ns = end - begin
|
|
checksum = total(state.values) + state.count - length(state.values)
|
|
} |
|
|
|
|
loop continuousRecordUpdate(ticks: Text) (samples: List<Sample>)
|
|
| each value in range(0, 10) | result |
|
|
| samples | list recordUpdate(ticks) |
|
|
|
|
flow recordInspect(ticks: Text) (sample: Sample)
|
|
| step | kind | do |
|
|
| input | calc | dever.bytes.fromText(ticks) |
|
|
| begin | flow | dever.time.monotonicNanos() |
|
|
| state | loop | inspectUpdates(input) |
|
|
| end | flow | dever.time.monotonicNanos() |
|
|
| sample | calc | Sample {
|
|
elapsed_ns = end - begin
|
|
checksum = total(state.values) + state.count - length(state.values)
|
|
} |
|
|
|
|
loop continuousRecordInspect(ticks: Text) (samples: List<Sample>)
|
|
| each value in range(0, 10) | result |
|
|
| samples | list recordInspect(ticks) |
|
|
|
|
flow mapLookup(ticks: Text) (sample: Sample)
|
|
| step | kind | do |
|
|
| input | calc | dever.bytes.fromText(ticks) |
|
|
| values | loop | buildMap(input) |
|
|
| initial | calc | Lookup { values = values, index = 0, total = 0 } |
|
|
| begin | flow | dever.time.monotonicNanos() |
|
|
| state | loop | lookupValues(input, initial) |
|
|
| end | flow | dever.time.monotonicNanos() |
|
|
| sample | calc | Sample { elapsed_ns = end - begin, checksum = state.total } |
|
|
|
|
loop continuousMapLookup(ticks: Text) (samples: List<Sample>)
|
|
| each value in range(0, 10) | result |
|
|
| samples | list mapLookup(ticks) |
|
|
|
|
flow mapTextLookup(ticks: Text) (sample: Sample)
|
|
| step | kind | do |
|
|
| input | calc | dever.bytes.fromText(ticks) |
|
|
| values | loop | textEntries(entries(buildMap(input))) |
|
|
| keys | loop | textKeys(entries(values)) |
|
|
| initial | calc | TextLookup { values = values, total = 0 } |
|
|
| begin | flow | dever.time.monotonicNanos() |
|
|
| state | loop | lookupText(keys, initial) |
|
|
| end | flow | dever.time.monotonicNanos() |
|
|
| sample | calc | Sample { elapsed_ns = end - begin, checksum = state.total + length(keys) - length(input) } |
|
|
|
|
loop continuousMapTextLookup(ticks: Text) (samples: List<Sample>)
|
|
| each value in range(0, 10) | result |
|
|
| samples | list mapTextLookup(ticks) |
|
|
|
|
flow textEqual(ticks: Text) (sample: Sample)
|
|
| step | kind | do |
|
|
| input | calc | dever.bytes.fromText(ticks) |
|
|
| rows | loop | textPairs(input) |
|
|
| begin | flow | dever.time.monotonicNanos() |
|
|
| value | loop | equalPairs(rows) |
|
|
| end | flow | dever.time.monotonicNanos() |
|
|
| sample | calc | Sample { elapsed_ns = end - begin, checksum = value + length(rows) - length(input) } |
|
|
|
|
loop continuousTextEqual(ticks: Text) (samples: List<Sample>)
|
|
| each value in range(0, 10) | result |
|
|
| samples | list textEqual(ticks) |
|
|
|
|
flow textContains(ticks: Text) (sample: Sample)
|
|
| step | kind | do |
|
|
| input | calc | dever.bytes.fromText(ticks) |
|
|
| rows | loop | textPairs(input) |
|
|
| begin | flow | dever.time.monotonicNanos() |
|
|
| value | loop | containsPairs(rows) |
|
|
| end | flow | dever.time.monotonicNanos() |
|
|
| sample | calc | Sample { elapsed_ns = end - begin, checksum = value + length(rows) - length(input) } |
|
|
|
|
loop continuousTextContains(ticks: Text) (samples: List<Sample>)
|
|
| each value in range(0, 10) | result |
|
|
| samples | list textContains(ticks) |
|
|
|
|
flow bytesConcat(ticks: Text) (sample: Sample)
|
|
| step | kind | do |
|
|
| chunks | loop | byteChunks(text.split(ticks, "")) |
|
|
| begin | flow | dever.time.monotonicNanos() |
|
|
| value | loop | joinBytes(chunks) |
|
|
| end | flow | dever.time.monotonicNanos() |
|
|
| sample | calc | Sample { elapsed_ns = end - begin, checksum = byteTotal(value) } |
|
|
|
|
loop continuousBytesConcat(ticks: Text) (samples: List<Sample>)
|
|
| each value in range(0, 10) | result |
|
|
| samples | list bytesConcat(ticks) |
|
|
|
|
flow textConcat(ticks: Text) (sample: Sample)
|
|
| step | kind | do |
|
|
| chunks | calc | text.split(ticks, ",") |
|
|
| begin | flow | dever.time.monotonicNanos() |
|
|
| value | loop | joinText(chunks) |
|
|
| end | flow | dever.time.monotonicNanos() |
|
|
| sample | calc | Sample { elapsed_ns = end - begin, checksum = byteTotal(dever.bytes.fromText(value)) } |
|
|
|
|
loop continuousTextConcat(ticks: Text) (samples: List<Sample>)
|
|
| each value in range(0, 10) | result |
|
|
| samples | list textConcat(ticks) |
|
|
|
|
putValue(value: Int, state: Map<Int, Int>) (out: Map<Int, Int>) {
|
|
out = put(state, length(state), value)
|
|
}
|
|
|
|
textEntry(entry: MapEntry<Int, Int>, state: Map<Text, Int>) (out: Map<Text, Int>) {
|
|
out = put(state, "lookup-key-" + int.toText(entry.key), entry.value)
|
|
}
|
|
|
|
appendText(value: Text, state: Text) (out: Text) {
|
|
out = state + value
|
|
}
|
|
|
|
appendBytes(value: Bytes, state: Bytes) (out: Bytes) {
|
|
out = dever.bytes.concat(state, value)
|
|
}
|