-
Notifications
You must be signed in to change notification settings - Fork 1
/
collect.awk
executable file
·124 lines (116 loc) · 2.2 KB
/
collect.awk
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/usr/bin/awk -f
# ugrep project auto-benchmarks https://github.com/Genivia/ugrep
BEGIN {
FS=" "
title=""
ncmd=0
nopt=0
nrex=0
}
END {
printf "\n\n"
}
/^`/ {
cmd=substr($1,2)
# ignore options -E and -I that are sometimes added to for fair performance comparisons
if ($2=="-E") {
if ($3=="-I") {
opt=$4
rex=$5
if (substr(opt,1,1)!="-" || substr(opt,1,2)=="-f") {
rex=opt
opt=""
}
}
else {
opt=$3
rex=$4
if (substr(opt,1,1)!="-" || substr(opt,1,2)=="-f") {
rex=opt
opt=""
}
}
}
else if ($2=="-I") {
opt=$3
rex=$4
if (substr(opt,1,1)!="-" || substr(opt,1,2)=="-f") {
rex=opt
opt=""
}
}
else {
opt=$2
rex=$3
if (substr(opt,1,1)!="-" || substr(opt,1,2)=="-f") {
rex=opt
opt=""
}
}
# remove trailing `
if (substr(rex,length(rex),1) == "`")
rex=substr(rex,1,length(rex)-1)
# arrays to maintain the order of commands, options and regex
if (!(cmd in cmds)) {
cmds[cmd]=1
icmds[ncmd++]=cmd
}
if (!(opt in opts)) {
opts[opt]=1
iopts[nopt++]=opt
}
if (!(rex in rexs)) {
rexs[rex]=1
irexs[nrex++]=rex
}
}
/^real [0-9]+\.[0-9]+/ {
perf[cmd,opt,rex]=$2
}
/^\*\*ERROR!\*\*/ {
perf[cmd,opt,rex]="*fail*"
}
/^## / {
if (title!="" && ncmd>0 && nopt>0 && nrex>0) {
printf "\n## results for %s\n",substr(title,4)
for (i=0; i<nrex; ++i) {
rex=irexs[i]
printf "\ngrepping `%s` elapsed real time (s)\n\n",rex
printf "| search |"
for (j=0; j<nopt; ++j)
printf " %6s |",iopts[j]
printf "\n| -----: |"
for (j=0; j<nopt; ++j)
printf " -----: |"
printf "\n"
for (j=0; j<ncmd; ++j) {
cmd=icmds[j]
printf "| %6s |",cmd
for (k=0; k<nopt; ++k) {
opt=iopts[k]
printf " %6s |",perf[cmd,opt,rex]
}
printf "\n"
}
}
}
title=$0
delete cmds
delete opts
delete rexs
delete icmds
delete iopts
delete irexs
ncmd=0
nopt=0
nrex=0
}
function cmp_str_val(i1, v1, i2, v2)
{
# string value comparison, ascending order
v1 = v1 ""
v2 = v2 ""
if (v1 < v2)
return -1
return (v1 != v2)
}