#!/bin/bash
# Create libtest.so
echo
echo "Compiling"
g++ -shared -fPIC test.cpp -o libtest.so
# link boost_regex before libtest.so
g++  main.cpp -lboost_regex${BOOST_EXT} -ltest -L${PWD} -o main_fast
# link boost_regex after libtest.so
g++  main.cpp -ltest -lboost_regex${BOOST_EXT} -L${PWD} -o main_slow

echo
echo "Testing slow version"
time env LD_LIBRARY_PATH=${PWD} ./main_slow
# real 0m0.753s, user 0m0.746s, sys 0m0.004s
echo
echo "Testing fast version"
time env LD_LIBRARY_PATH=${PWD} ./main_fast
# real 0m0.104s, user 0m0.103s, sys 0m0.002s

echo
echo "Testing slow version with optimized library"
g++ -O -shared -fPIC test.cpp -o libtest2.so
g++  main.cpp -ltest2 -lboost_regex${BOOST_EXT} -L${PWD} -o main_slow2
time env LD_LIBRARY_PATH=${PWD} ./main_slow2
# real 0m0.118s, user 0m0.115s, sys 0m0.003s

echo
echo "Testing unoptimized static build"
g++ main.cpp test.cpp -o main_test -l boost_regex
time ./main_test
# real 0m0.645s, user 0m0.641s, sys 0m0.001s
