60 lines
1.5 KiB
Plaintext
60 lines
1.5 KiB
Plaintext
; Benchmark scaffold fixture for local-machine parse timing comparisons only.
|
|
|
|
(module main)
|
|
|
|
(fn loop_count () -> i32
|
|
1000000)
|
|
|
|
(fn expected_checksum () -> i32
|
|
345000001)
|
|
|
|
(fn parse_stdin_loop_count () -> (result i32 i32)
|
|
(let input (result string i32) (std.io.read_stdin_result))
|
|
(match input
|
|
((ok text)
|
|
(std.string.parse_i32_result text))
|
|
((err code)
|
|
(err i32 i32 code))))
|
|
|
|
(fn parse_arg_loop_count () -> (result i32 i32)
|
|
(std.string.parse_i32_result (std.process.arg 2)))
|
|
|
|
(fn configured_stdin_loop_count () -> i32
|
|
(let parsed_stdin (result i32 i32) (parse_stdin_loop_count))
|
|
(if (is_ok parsed_stdin)
|
|
(unwrap_ok parsed_stdin)
|
|
(loop_count)))
|
|
|
|
(fn configured_loop_count () -> i32
|
|
(let parsed_arg (result i32 i32) (parse_arg_loop_count))
|
|
(if (is_ok parsed_arg)
|
|
(unwrap_ok parsed_arg)
|
|
(configured_stdin_loop_count)))
|
|
|
|
(fn parse_text () -> string
|
|
(std.process.arg 1))
|
|
|
|
(fn parsed_value ((text string)) -> i32
|
|
(unwrap_ok (std.string.parse_i32_result text)))
|
|
|
|
(fn parse_loop ((limit i32) (text string)) -> i32
|
|
(var i i32 0)
|
|
(var acc i32 1)
|
|
(while (< i limit)
|
|
(set acc (+ acc (parsed_value text)))
|
|
(set acc (if (> acc 1000000000)
|
|
(- acc 1000000000)
|
|
acc))
|
|
(set i (+ i 1)))
|
|
acc)
|
|
|
|
(fn main () -> i32
|
|
(let result i32 (parse_loop (configured_loop_count) (parse_text)))
|
|
(std.io.print_i32 result)
|
|
(if (= result (expected_checksum))
|
|
0
|
|
1))
|
|
|
|
(test "parse loop checksum is deterministic"
|
|
(= (parse_loop (loop_count) "12345") (expected_checksum)))
|