#!/bin/bash
# testing performance of perl php ruby python java lua

ITR="0 1 2 3"
function runtests {
echo Testing $TT
TTF="${TT}_test.data.txt"
date >> $TTF
$1 >> $TTF 2>&1
for i in $ITR
do
	echo running pass $i
	echo :::::::: pass $i >> $TTF
	if [ $i == 0 ]; then
		PP=`pidof $TT`
		if [ -z "$PP" ]; then 
		    #run first pass with
		    $TT $TTS | ./runtest.sh $TT $TTF
		else
		    echo "ERROR: '$TT' should not be running"
		    exit 1
		fi
	else
		$TT $TTS >> $TTF
	fi
	echo >> $TTF
done
}


TT='perl'
TTS='./perl_test.pl'
runtests "${TT} --version"

TT='php-cgi'
TTS='./php_test.php'
runtests "${TT} --version"

TT='ruby'
TTS='./ruby_test.ruby'
runtests "${TT} --version"

TT='python'
TTS='./python_test.py'
runtests "${TT} --version"

TT='python3'
TTS='./python3_test.py'
runtests "${TT} --version"

TT='cpp_test'
TTF="${TT}.data.txt"
g++ cpp_test.cpp -o $TT
g++ --version > $TTF
./$TT | ./runtest.sh $TT $TTF

TT='c_test'
TTF="${TT}.data.txt"
gcc c_test.c -o $TT
gcc --version > $TTF
./$TT | ./runtest.sh $TT $TTF

TT='clang_test'
TTF="${TT}.data.txt"
clang c_test.c -O3 -o $TT
clang --version > $TTF
./$TT | ./runtest.sh $TT $TTF

TT='shell'
TTF="jsv8.data.txt"
./v8/$TT ./v8/javascript_test.js | ./runtest.sh $TT $TTF

#too slow to do 5 passes
ITR="0"

#/usr/lib/jvm/java-6-openjdk/jre/bin/
TT='java'
TTS='java_test'
javac "${TTS}.java"
runtests "${TT} -version"

### GCJ java test
gcj -c -g -O java_test.java && gcj --main=java_test -o java_test java_test.o
TT='java_test'
TTF="${TT}.data_gcj.txt"
gcj --version > $TTF
./$TT | ./runtest.sh $TT $TTF

TT='lua'
TTS='./lua_test.lua'
runtests "${TT} -v"

TT='tclsh'
TTS='./tcl_test.tcl'
TTF="${TT}_test.data.txt"
echo 'puts $tcl_patchLevel'|tclsh>$TTF
#runtests

TT='smjs'
TTS='./javascript_test.js'
runtests "${TT} --version"

