diff options
author | Indrajith K L | 2022-12-03 17:00:20 +0530 |
---|---|---|
committer | Indrajith K L | 2022-12-03 17:00:20 +0530 |
commit | f5c4671bfbad96bf346bd7e9a21fc4317b4959df (patch) | |
tree | 2764fc62da58f2ba8da7ed341643fc359873142f /v_windows/v/old/vlib/benchmark/README.md | |
download | cli-tools-windows-f5c4671bfbad96bf346bd7e9a21fc4317b4959df.tar.gz cli-tools-windows-f5c4671bfbad96bf346bd7e9a21fc4317b4959df.tar.bz2 cli-tools-windows-f5c4671bfbad96bf346bd7e9a21fc4317b4959df.zip |
Diffstat (limited to 'v_windows/v/old/vlib/benchmark/README.md')
-rw-r--r-- | v_windows/v/old/vlib/benchmark/README.md | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/v_windows/v/old/vlib/benchmark/README.md b/v_windows/v/old/vlib/benchmark/README.md new file mode 100644 index 0000000..6f4f7db --- /dev/null +++ b/v_windows/v/old/vlib/benchmark/README.md @@ -0,0 +1,45 @@ +Example usage of this module: +```v +import benchmark + +mut bmark := benchmark.new_benchmark() +// by default the benchmark will be verbose, i.e. it will include timing information +// if you want it to be silent, set bmark.verbose = false +for { + bmark.step() // call this when you want to advance the benchmark. + // The timing info in bmark.step_message will be measured starting from the last call to bmark.step + // .... + // bmark.fail() // call this if the step failed + // bmark.step_message(('failed') + bmark.ok() // call this when the step succeeded + println(bmark.step_message('ok')) +} +bmark.stop() +// call when you want to finalize the benchmark +println(bmark.total_message('remarks about the benchmark')) +``` + +benchmark.start() and b.measure() are convenience methods, +intended to be used in combination. Their goal is to make +benchmarking of small snippets of code as *short*, easy to +write, and then to read and analyze the results, as possible. + +Example: +```v +import time +import benchmark + +mut b := benchmark.start() +// your code section 1 ... +time.sleep(1500 * time.millisecond) +b.measure('code_1') +// your code section 2 ... +time.sleep(500 * time.millisecond) +b.measure('code_2') +``` + +... which will produce on stdout something like this: +```text +SPENT 1500.063 ms in code_1 +SPENT 500.061 ms in code_2 +``` |