7.4 KiB
module benchmark
Contents
Constants
const b_ok = term.ok_message('OK ')
const b_fail = term.fail_message('FAIL')
const b_skip = term.warn_message('SKIP')
const b_spent = term.ok_message('SPENT')
new_benchmark
fn new_benchmark() Benchmark
new_benchmark returns a Benchmark instance on the stack.
new_benchmark_no_cstep
fn new_benchmark_no_cstep() Benchmark
new_benchmark_no_cstep returns a new Benchmark instance with step counting disabled.
new_benchmark_pointer
fn new_benchmark_pointer() &Benchmark
new_benchmark_pointer returns a new Benchmark instance allocated on the heap. This is useful for long-lived use of Benchmark instances.
start
fn start() Benchmark
start returns a new, running, instance of Benchmark. This is a shorthand for calling new_benchmark().step().
Benchmark
struct Benchmark {
pub mut:
bench_timer time.StopWatch
verbose bool
no_cstep bool
step_timer time.StopWatch
ntotal int
nok int
nfail int
nskip int
nexpected_steps int
njobs int
cstep int
bok string
bfail string
measured_steps []string
step_data map[string][]f64
}
set_total_expected_steps
fn (mut b Benchmark) set_total_expected_steps(n int)
set_total_expected_steps sets the total amount of steps the benchmark is expected to take.
stop
fn (mut b Benchmark) stop()
stop stops the internal benchmark timer.
step
fn (mut b Benchmark) step()
step increases the step count by 1 and restarts the internal timer.
step_restart
fn (mut b Benchmark) step_restart()
step_restart will restart the internal step timer. Note that the step count will stay the same. This method is useful, when you want to do some optional preparation after you have called .step(), so that the time for that optional preparation will not be added to the duration of the step.
fail
fn (mut b Benchmark) fail()
fail increases the fail count by 1 and stops the internal timer.
ok
fn (mut b Benchmark) ok()
ok increases the ok count by 1 and stops the internal timer.
skip
fn (mut b Benchmark) skip()
skip increases the skip count by 1 and stops the internal timer.
fail_many
fn (mut b Benchmark) fail_many(n int)
fail_many increases the fail count by n and stops the internal timer.
ok_many
fn (mut b Benchmark) ok_many(n int)
ok_many increases the ok count by n and stops the internal timer.
neither_fail_nor_ok
fn (mut b Benchmark) neither_fail_nor_ok()
neither_fail_nor_ok stops the internal timer.
measure
fn (mut b Benchmark) measure(label string) i64
measure prints the current time spent doing label, since the benchmark was started, or since its last call.
record_measure
fn (mut b Benchmark) record_measure(label string) i64
record_measure stores the current time doing label, since the benchmark was started, or since the last call to b.record_measure. It is similar to b.measure, but unlike it, will not print the measurement immediately, just record it for later. You can call b.all_recorded_measures to retrieve all measures stored by b.record_measure calls.
step_message_with_label_and_duration
fn (b &Benchmark) step_message_with_label_and_duration(label string, msg string, sduration time.Duration,
opts MessageOptions) string
step_message_with_label_and_duration returns a string describing the current step.
step_message_with_label
fn (b &Benchmark) step_message_with_label(label string, msg string, opts MessageOptions) string
step_message_with_label returns a string describing the current step using current time as duration.
step_message
fn (b &Benchmark) step_message(msg string, opts MessageOptions) string
step_message returns a string describing the current step.
step_message_ok
fn (b &Benchmark) step_message_ok(msg string, opts MessageOptions) string
step_message_ok returns a string describing the current step with an standard "OK" label.
step_message_fail
fn (b &Benchmark) step_message_fail(msg string, opts MessageOptions) string
step_message_fail returns a string describing the current step with an standard "FAIL" label.
step_message_skip
fn (b &Benchmark) step_message_skip(msg string, opts MessageOptions) string
step_message_skip returns a string describing the current step with an standard "SKIP" label.
total_message
fn (b &Benchmark) total_message(msg string) string
total_message returns a string with total summary of the benchmark run.
all_recorded_measures
fn (b &Benchmark) all_recorded_measures() string
all_recorded_measures returns a string, that contains all the recorded measure messages, done by individual calls to b.record_measure.
total_duration
fn (b &Benchmark) total_duration() i64
total_duration returns the duration in ms.
MessageOptions
struct MessageOptions {
pub:
preparation time.Duration // the duration of the preparation time for the step
}
MessageOptions allows passing an optional preparation time too to each label method. If it is set, the preparation time (compile time) will be shown before the measured runtime.