summaryrefslogtreecommitdiffstats
path: root/contrib/benchmarks/run.sh
blob: 388c6013827180a4dc816a291c23f7c4e447dc6f (plain)
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
#!/bin/bash
ME=`basename $0`
DIR="$( cd "$( dirname "$0" )" && pwd )"
CWD=`pwd`
cd ${DIR}

TIMEOUT=25s

RUN_QT=false
RUN_APACHE=false
RUN_SCION=false
RUN_SCXMLCC=false
RUN_USCXML=false
RUN_LXSC=false

PLOT=false

PATTERN='*.scxml'

if [ ! -d "./logs" ]; then
	mkdir logs
fi

# https://superuser.com/a/473715
function canonicalPath
{
    local path="$1" ; shift
    if [ -d "$path" ]
    then
        echo "$(cd "$path" ; pwd)"
    else
        local b=$(basename "$path")
        local p=$(dirname "$path")
        echo "$(cd "$p" ; pwd)/$b"
    fi
}

# ===== qt ================
function init-qt {
	cd qt
	if [ ! -x "./build/StatesPerSecond" ]; then
		mkdir build
		cd build
		qmake ..
		make
		cd ..
	fi
	cd ..
}

function run-qt {
	BENCHMARK=$1 
	SC_NAME=$2
	export USCXML_BENCHMARK=${BENCHMARK}

	cd qt/build
	make
	timeout ${TIMEOUT} ./StatesPerSecond |tee ../../logs/${SC_NAME}-qt.log
	cd ../..
}

function clean-qt {
	cd qt
	rm -rf build
	cd ..
}

# ===== APACHE ================
function init-apache {
	cd apache
	mvn compile
	cd ..
}

function run-apache {
	BENCHMARK=$1 
	SC_NAME=$2
	export USCXML_BENCHMARK=${BENCHMARK}

	cd apache
	timeout ${TIMEOUT} mvn test |tee ../logs/${SC_NAME}-apache.log
	cd ..

}

function clean-apache {
	cd apache
	rm -rf target
	cd ..
}


# ===== USCXML ================
function init-uscxml {
	cd uscxml
	if [ ! -x "./statesPerSecond" ]; then
		g++ -std=c++11 \
		./statesPerSecond.cpp \
		-I/usr/local/include \
		-I../../../build/cli/deps/xerces-c/include/ \
		-luscxml \
		-L ../../../build/cli/deps/xerces-c/lib/ \
		-lxerces-c \
		-o statesPerSecond
	fi
	cd ..
}

function run-uscxml {
	BENCHMARK=$1 
	SC_NAME=$2

	cd uscxml
	timeout ${TIMEOUT} ./statesPerSecond ${BENCHMARK} fast |tee ../logs/${SC_NAME}-uscxml-fast.log
	timeout ${TIMEOUT} ./statesPerSecond ${BENCHMARK} large |tee ../logs/${SC_NAME}-uscxml-large.log
	cd ..
}

function clean-uscxml {
	cd uscxml
	rm statesPerSecond
	cd ..

}

# ===== LXSC ================
function init-lxsc {
	cd lxsc

	if [ ! -d "./lxsc" ]; then
		git clone https://github.com/Phrogz/LXSC.git
		# increase microstep sequence considerably
		sed -i '.bak' 's/S\.MAX_ITERATIONS\ =\ 1000/S\.MAX_ITERATIONS\ =\ 1000000/' ./LXSC/lib/runtime.lua
	fi

	cd ..
}

function run-lxsc {
	BENCHMARK=$1 
	SC_NAME=$2

	cd lxsc
	timeout ${TIMEOUT} lua ./statesPerSecond.lua ${BENCHMARK} |tee ../logs/${SC_NAME}-lxsc.log
	cd ..
}

function clean-lxsc {
	cd lxsc
	rm -rf LXSC
	cd ..
}

# ===== SCION ================
function init-scion {
	cd scion
	if [ ! -d "./node_modules" ]; then
		npm install scxml babel-polyfill
	fi
	cd ..
}

function run-scion {
	BENCHMARK=$1 
	SC_NAME=$2

	cd scion

	timeout ${TIMEOUT} node ./statesPerSecond.js ${BENCHMARK} |tee ../logs/${SC_NAME}-scion.log

	cd ..
}

function clean-scion {
	cd scion
	rm -rf node_modules
	cd ..
}

# ===== SCXMLCC ================
function init-scxmlcc {
	cd scxmlcc

	# check out from git
	if [ ! -d "./scxmlcc" ]; then
		git clone https://github.com/jp-embedded/scxmlcc.git
	fi

	# compile transpiler
	if [ ! -x "./scxmlcc/src/scxmlcc" ]; then
		export CXXFLAGS=-I/opt/local/include
		cp ./makefile scxmlcc/src
		cd scxmlcc/src
		touch version_auto.h 
		make
		cd ../..
	fi

	cd ..
}

function run-scxmlcc {
	BENCHMARK=$1 
	SC_NAME=$2

	cd scxmlcc
	rm test
	timeout ${TIMEOUT} ./scxmlcc/src/scxmlcc -i ${BENCHMARK} -o ./test.h
	timeout ${TIMEOUT} g++ -DMACHINE_NAME=sc_benchmark ./statesPerSecond.cpp -o test
	timeout ${TIMEOUT} ./test |tee ../logs/${SC_NAME}-scxmlcc.log

	cd ..
}

function clean-scxmlcc {
	cd scxmlcc
	rm -rf logs
	rm -rf scxmlcc
	rm test
	rm test.h
	cd ..
}  


# =======================================
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
		-p|--pattern)
		PATTERN="$2"
		;;

		-p|--plot)
		
		;;
		-c|--clean)
		clean-scxmlcc
		clean-scion
		clean-lxsc
		clean-uscxml
		clean-apache
		clean-qt
		rm -rf logs
		exit
		;;

		--all)
		init-scxmlcc
		init-uscxml
		init-lxsc
		init-scion
		init-apache
		init-qt
		RUN_QT=true
		RUN_APACHE=true
		RUN_SCXMLCC=true
		RUN_USCXML=true
		RUN_LXSC=true
		RUN_SCION=true
		;;

		--scxmlcc)
		init-scxmlcc
		RUN_SCXMLCC=true
		;;

		--uscxml)
		init-uscxml
		RUN_USCXML=true
		;;

		--lxsc)
		init-lxsc
		RUN_LXSC=true
		;;

		--qt)
		init-qt
		RUN_QT=true
		;;

		--scion)
		init-scion
		RUN_SCION=true
		;;

		--apache)
		init-apache
		RUN_APACHE=true
		;;

		*)
		;;
esac
shift # past argument or value
done

BENCHMARKS=`find $(pwd)/../../test/benchmarks -type f -name ${PATTERN}`

for BENCHMARK in $BENCHMARKS
do
	BENCHMARK=$(canonicalPath $BENCHMARK)

	SC_NAME=$(basename "$BENCHMARK" .scxml)

	echo "== Running ${SC_NAME} from ${BENCHMARK}"
	
	if [ "$RUN_SCION" = true ] ; then
		echo "==== with SCION"
		run-scion ${BENCHMARK} ${SC_NAME}
	fi 

	if [ "$RUN_SCXMLCC" = true ] ; then
		echo "==== with SCXMLCC"
		run-scxmlcc ${BENCHMARK} ${SC_NAME}
	fi 

	if [ "$RUN_LXSC" = true ] ; then
		echo "==== with LXSC"
		run-lxsc ${BENCHMARK} ${SC_NAME}
	fi 

	if [ "$RUN_QT" = true ] ; then
		echo "==== with QT"
		run-qt ${BENCHMARK} ${SC_NAME}
	fi 

	if [ "$RUN_USCXML" = true ] ; then
		echo "==== with USCXML"
		run-uscxml ${BENCHMARK} ${SC_NAME}
	fi 

	if [ "$RUN_APACHE" = true ] ; then
		echo "==== with APACHE"
		run-apache ${BENCHMARK} ${SC_NAME}
	fi 

done
sed -i '.bak' '/^[0-9\.]*, [0-9\.]*/!d' ./logs/*.log
rm -f logs/*.bak

if [ "$PLOT" = true ] ; then
	./plot.sh
fi