-
Notifications
You must be signed in to change notification settings - Fork 1
/
sample.v
40 lines (32 loc) · 1.16 KB
/
sample.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import bench
import time
fn main(){
println('starting test')
mut b := bench.new(bench.Benchmark{
bench_secs: 4,
})
b.bench('sleep short', sleep_short)
b.bench('sleep shorter', sleep_shorter)
b.bench('alloc_some', alloc_some)
}
fn sleep_short(){
time.sleep_ms(10)
}
fn sleep_shorter(){
time.sleep_ms(1)
}
fn alloc_some(){
mut s_arr := []string{}
for i := 0; i < 100000; i++{
s_arr << i.str()
}
}
// Output:
// starting test
// sleep short mean:87.04ips (11.49ms) variance:0.00000 relative_stddev:2.066 [44 cycles|8 ops]
// sleep shorter mean:777.63ips (1.29ms) variance:0.00003 relative_stddev:0.732 [41 cycles|77 ops]
// alloc_some mean:134.87ips (7.41ms) variance:0.00001 relative_stddev:2.040 [42 cycles|13 ops]
// starting test
// sleep short mean:86.43ips (11.57ms) variance:0.00000 relative_stddev:2.085 [43 cycles|8 ops]
// sleep shorter mean:780.53ips (1.28ms) variance:0.00005 relative_stddev:0.926 [41 cycles|77 ops]
// alloc_some mean:135.85ips (7.36ms) variance:0.00001 relative_stddev:2.558 [42 cycles|13 ops]