mirror of
https://github.com/vlang/v.git
synced 2025-09-13 14:32:26 +03:00
This commit is contained in:
parent
d130939ad6
commit
673ac0a411
4 changed files with 109 additions and 0 deletions
19
cmd/tools/bench/map_clear.v
Normal file
19
cmd/tools/bench/map_clear.v
Normal file
|
@ -0,0 +1,19 @@
|
|||
import benchmark
|
||||
|
||||
fn main() {
|
||||
max_iterations := arguments()[1] or { '1_000_000' }.int()
|
||||
assert max_iterations > 0
|
||||
mut m := {
|
||||
123: 456
|
||||
789: 321
|
||||
}
|
||||
mut volatile sum := u64(0)
|
||||
mut b := benchmark.start()
|
||||
for i in 0 .. max_iterations {
|
||||
m.clear()
|
||||
m[i] = i * 2
|
||||
sum += u64(m.len)
|
||||
}
|
||||
assert m.len == 1
|
||||
b.measure('m.clear(), iterations: ${max_iterations}, sum: ${sum}')
|
||||
}
|
23
cmd/tools/bench/map_clear_runner.vsh
Executable file
23
cmd/tools/bench/map_clear_runner.vsh
Executable file
|
@ -0,0 +1,23 @@
|
|||
#!/usr/bin/env -S v -raw-vsh-tmp-prefix tmp
|
||||
|
||||
import os
|
||||
|
||||
const time_fmt = '"CPU: %Us\tReal: %es\tElapsed: %E\tRAM: %MKB\t%C"'
|
||||
const flags = os.getenv('FLAGS')
|
||||
|
||||
unbuffer_stdout()
|
||||
|
||||
start := os.args[1] or { '1_000_000' }.int()
|
||||
end := os.args[2] or { '10_000_000' }.int()
|
||||
step := os.args[3] or { '500_000' }.int()
|
||||
|
||||
os.chdir(os.dir(@VEXE))!
|
||||
vcmd := 'v ${flags} cmd/tools/bench/map_clear.v'
|
||||
|
||||
println('>> start: ${start} | end: ${end} | step: ${step} | workdir: "${os.getwd()}" | flags: "${flags}" | vcmd: "${vcmd}"')
|
||||
assert os.system(vcmd) == 0
|
||||
|
||||
println('running...')
|
||||
for i := start; i <= end; i += step {
|
||||
os.system('/usr/bin/time -f ${time_fmt} cmd/tools/bench/map_clear ${i}') == 0
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue