Files
herolib/aiprompts/v_core/benchmark/benchmark.md
2025-09-02 07:28:13 +02:00

7.4 KiB

module benchmark

Contents

Constants

const b_ok = term.ok_message('OK  ')

[Return to contents]

const b_fail = term.fail_message('FAIL')

[Return to contents]

const b_skip = term.warn_message('SKIP')

[Return to contents]

const b_spent = term.ok_message('SPENT')

[Return to contents]

new_benchmark

fn new_benchmark() Benchmark

new_benchmark returns a Benchmark instance on the stack.

[Return to contents]

new_benchmark_no_cstep

fn new_benchmark_no_cstep() Benchmark

new_benchmark_no_cstep returns a new Benchmark instance with step counting disabled.

[Return to contents]

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.

[Return to contents]

start

fn start() Benchmark

start returns a new, running, instance of Benchmark. This is a shorthand for calling new_benchmark().step().

[Return to contents]

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
}

[Return to contents]

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.

[Return to contents]

stop

fn (mut b Benchmark) stop()

stop stops the internal benchmark timer.

[Return to contents]

step

fn (mut b Benchmark) step()

step increases the step count by 1 and restarts the internal timer.

[Return to contents]

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.

[Return to contents]

fail

fn (mut b Benchmark) fail()

fail increases the fail count by 1 and stops the internal timer.

[Return to contents]

ok

fn (mut b Benchmark) ok()

ok increases the ok count by 1 and stops the internal timer.

[Return to contents]

skip

fn (mut b Benchmark) skip()

skip increases the skip count by 1 and stops the internal timer.

[Return to contents]

fail_many

fn (mut b Benchmark) fail_many(n int)

fail_many increases the fail count by n and stops the internal timer.

[Return to contents]

ok_many

fn (mut b Benchmark) ok_many(n int)

ok_many increases the ok count by n and stops the internal timer.

[Return to contents]

neither_fail_nor_ok

fn (mut b Benchmark) neither_fail_nor_ok()

neither_fail_nor_ok stops the internal timer.

[Return to contents]

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.

[Return to contents]

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.

[Return to contents]

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.

[Return to contents]

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.

[Return to contents]

step_message

fn (b &Benchmark) step_message(msg string, opts MessageOptions) string

step_message returns a string describing the current step.

[Return to contents]

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.

[Return to contents]

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.

[Return to contents]

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.

[Return to contents]

total_message

fn (b &Benchmark) total_message(msg string) string

total_message returns a string with total summary of the benchmark run.

[Return to contents]

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.

[Return to contents]

total_duration

fn (b &Benchmark) total_duration() i64

total_duration returns the duration in ms.

[Return to contents]

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.

[Return to contents]

Powered by vdoc. Generated on: 2 Sep 2025 07:21:08