#!/bin/bash -e
#
# generate list.txt and run the test programs
#


f=list.txt

# generate list.txt using random data
#test -f $f || ./gen_cvs2.awk

# generate list.txt using deterministic data
test -f $f || ./gen_cvs.exe

true <$f || exit

if ! test -f nodup_soll.txt
then
    # generate nodup_soll.txt for comparison
    ./test_hans.exe
    cp nodup.txt nodup_soll.txt
fi

lines=`wc -l < $f`
bytes=`wc -c < $f`

# calc function
calc() { gawk "BEGIN { print $1; }"; }

for prog in test_mikro77_awk.sh test_foobar_lua.sh test_mh_python.sh \
    test_hans.exe \
    test_heinzel.exe test_heinzel2.exe \
    test_foobar3.exe test_foobar2.exe \
    test_win_native.exe
do
    n1=$EPOCHREALTIME; ./$prog; n2=$EPOCHREALTIME

    tm=`calc "$n2 - $n1"` 
    bps=`calc "$bytes / ($n2 - $n1) * 1e-6"`
    lps=`calc "$lines / ($n2 - $n1) * 1e0"`

    diff -q nodup.txt nodup_soll.txt

    progbytes=`wc -c < $prog`

    printf '%-25s Progsize=%-7d Seconds=%-6.2f MB/sec=%-6.2f Lines/sec=%-6.0f\n' $prog $progbytes $tm $bps $lps
done
