#!/usr/bin/bash
# do_strhash_test     see license.txt for copyright and terms of use

# dsw: compare two different implementations of smbase/strhash

# FIX: it would be nice to tee the output to a file and have a perl
# script compute the time ratio for us automatically

SMBASE=.

set -x

# using the longest .cc file in smbase
TEST_FILE=srcloc.cc
if ! test -f $TEST_FILE; then
    echo "Test file does not exist: " $TEST_FILE
    exit 1;
fi

function buildit() {
    STRHASH_ALG=$1
    echo "Building hashing algorithm $STRHASH_ALG"
    # I'm pretty sure I have to rebuild the whole of smbase to make
    # sure that, say, profiling is off
    ./configure.pl -nodebug -DSTRHASH_ALG=$STRHASH_ALG -DSAY_STRHASH_ALG
    make -C $SMBASE clean all strhash
    rm -f strhash_$STRHASH_ALG
    mv $SMBASE/strhash strhash_$STRHASH_ALG
}

function testit() {
    STRHASH_ALG=$1
    echo "Testing hashing algorithm $STRHASH_ALG"
    ./strhash_$STRHASH_ALG --no-testCor --numPerfRuns 30000 --file $TEST_FILE
}

buildit 1
buildit 2

testit 1
testit 2
