-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.v
More file actions
80 lines (64 loc) · 1.45 KB
/
Copy pathmain.v
File metadata and controls
80 lines (64 loc) · 1.45 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
module main
// import bench
import time
struct Testfixture{
mut:
num int
}
fn main(){
// mut b := bench.new(bench.Benchmark{
// bench_secs: 10,
// verbose: false
// })
// b.bench('org 1', org)
// b.bench('upd 1', upd)
// b.bench('org 2', org)
// b.bench('upd 2', upd)
// b.bench('sleep short', sleep_short)
// b.bench('sleep shorter', sleep_shorter)
// b.bench('alloc_some', alloc_some)
s := 'a\nb\nc\nd'
println('org =${org(s)}')
println('org =${s.split_into_lines()}')
println('upd =${upd(s)}')
}
fn org(s string) []string {
// mut t := Testfixture{}
// s := 'this \n is a test \n string that needs \n to be tested\nand'
mut res := []string{}
if s.len == 0 {
return res
}
mut start := 0
for i := 0; i < s.len; i++ {
last := i == s.len - 1
if int(s[i]) == 10 || last {
if last {
i++
}
line := s.substr(start, i)
res << line
start = i + 1
}
}
return res
}
fn upd(s string) []string {
//mut t := Testfixture{}
//s := 'this \n is a test \n string that needs \n to be tested\nand'
x := s.split('\n')
//t.num = x.len
return x
}
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()
}
}