-
Notifications
You must be signed in to change notification settings - Fork 0
/
bench
executable file
·205 lines (183 loc) · 4.05 KB
/
bench
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#!/bin/sh
set -e
tests="*/"
while getopts t: name
do
case $name in
t) tests="$OPTARG";;
?) printf "usage: %s: [-t tests...]\n" $0
exit 2;;
esac
done
shift $(($OPTIND - 1))
unset name
command=/usr/bin/time
options=-p
clean() {
# C/C++
if [ -f makefile ]
then
make -s clean
else
rm -f a.out
fi
# Go
rm -f $1
# Java
rm -f "$(classname $1)".class
}
# backup - backup files as *.orig
# usage: backup source_file...
backup() {
for source_file in $@
do
target_file=${source_file}.orig
if [ -f $source_file ]
then
mv -f $source_file $target_file
fi
unset target_file
done
unset source_file
}
# restore - restore files from *.orig and ~
# usage: restore source_file...
restore() {
for source_file in $@
do
if [ -f $source_file ]
then
target_file=${source_file%.orig}
if [ $source_file != $target_file ]
then
mv -f $source_file $target_file
fi
fi
if [ -f $source_file ]
then
target_file=${source_file%~}
if [ $source_file != $target_file ]
then
mv -f $source_file $target_file
fi
fi
unset target_file
done
unset source_file
}
capitalize() {
read input
printf "%s" $input | awk '{ print toupper(substr($0, 1, 1)) substr($0, 2) }'
unset input
}
classname() {
echo ${1}App | capitalize
}
for d in $tests
do
file=$(basename $d)
cd $file
echo $file
clean $file
# C
if [ -f ${file}.c ]
then
restore *.c* *.cpp*
if [ -f makefile ]
then
make -s
else
# ISO POSIX-2:1993
c89 ${file}.c
fi
printf " %s\t" c
$command $options ./a.out 2>&1 \
| tr -s '\n' '\t'
printf '\n'
fi
# C++
if [ -f ${file}.cpp ]
then
if [ -f makefile ]
then
make -s c++
else
# CXX
g++ ${file}.cpp
fi
printf " %s\t" cpp
$command $options ./a.out 2>&1 \
| tr -s '\n' '\t'
printf '\n'
fi
# Go
# C/C++ source files not allowed when not using cgo or SWIG
# Avoid setting CGO_ENABLED=0, backup and restore instead
if [ -f ${file}.go ] \
&& command -v go > /dev/null
then
backup *.c *.cpp
go build ./...
restore *.c* *.cpp*
printf " %s\t" go
$command $options ./${file} 2>&1 \
| tr -s '\n' '\t'
printf '\n'
fi
# Java
if [ -f ${file}.java ] \
&& command -v javac > /dev/null \
&& command -v java > /dev/null
then
javac -cp '.:*' ${file}.java
printf " %s\t" java
class=$(classname $file)
$command $options java -cp '.:*' $class 2>&1 \
| tr -s '\n' '\t'
printf '\n'
unset class
fi
# Node
if [ -f ${file}.js ] \
&& command -v node > /dev/null
then
printf " %s\t" js
# nvm
# sudo ln -s $(which node) /usr/local/bin/node
$command $options node --max-old-space-size=8192 ${file}.js 2>&1 \
| tr -s '\n' '\t'
printf '\n'
fi
# Lua/LuaJIT
if [ -f ${file}.lua ]
then
if command -v lua > /dev/null
then
if [ -f makefile ]
then
make -s lua
fi
printf " %s\t" lua
# macOS
# cd /opt/homebrew/bin/
# ln -s ../Cellar/[email protected]/5.1.5_8/bin/lua-5.1 lua
$command $options lua ${file}.lua 2>&1 \
| tr -s '\n' '\t'
printf '\n'
fi
if command -v luajit > /dev/null
then
if [ -f makefile ]
then
make -s clean luajit
fi
printf " %s\t" luajit
$command $options luajit ${file}.lua 2>&1 \
| tr -s '\n' '\t'
printf '\n'
fi
fi
cd ..
unset file
done
unset d