1#! /bin/bash -e
2# -----------------------------------------------------------------------------
3# CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-18 Bradley M. Bell
4#
5# CppAD is distributed under the terms of the
6#              Eclipse Public License Version 2.0.
7#
8# This Source Code may also be made available under the following
9# Secondary License when the conditions for such availability set forth
10# in the Eclipse Public License, Version 2.0 are satisfied:
11#       GNU General Public License, Version 2.0 or later.
12# -----------------------------------------------------------------------------
13program="bin/speed_new.sh"
14if [ "$0" != "$program" ]
15then
16    echo "$program: must be executed from its parent directory"
17    exit 1
18fi
19if [ "$1" == '' ]
20then
21cat << EOF
22usage:
23$program test_name [option_1] [option_2] ...
24
25possible test are:
26all, det_lu, det_minor, mat_mul ode, poly, sparse_hessian, sparse_jacobian
27
28possible options are:
29atomic, boolsparsity, colpack, memory, onetape, optimize, revsparsity
30EOF
31    exit 1
32fi
33if [ ! -d new ]
34then
35    echo "$program: the directory ./new does not exist."
36    echo 'It should contain the new source code.'
37    exit 1
38fi
39test_name="$1"
40shift
41option_list="$test_name"
42for option in $*
43do
44    option_list="${option_list}_$option"
45done
46if [ "$test_name" == 'all' ]
47then
48    test_name='speed'
49fi
50# ----------------------------------------------------------------------------
51build_dir='build/speed/cppad'
52if [ ! -e $build_dir ]
53then
54    echo_eval mkdir -p $build_dir
55fi
56# ----------------------------------------------------------------------------
57# bash function that echos and executes a command
58echo_eval() {
59    echo $*
60    eval $*
61}
62# ----------------------------------------------------------------------------
63echo "bin/run_cmake.sh --debug_none > /dev/null"
64bin/run_cmake.sh --debug_none > /dev/null
65#
66for name in cur new
67do
68    if [ "$name" == 'cur' ]
69    then
70        # revert cppad source code to the current version
71        echo_eval git reset --hard --quiet
72    else
73        echo_eval git_new.sh from
74    fi
75    out_file="$name.$option_list.out"
76    if [ -e "$build_dir/$out_file" ]
77    then
78        echo "Using existing $build_dir/$out_file"
79    else
80        # change into cppad speed directory
81        echo_eval cd $build_dir
82        #
83        # compile the speed test
84        echo "make check_speed_cppad > $build_dir/$name.log"
85        make check_speed_cppad > $name.log
86        #
87        # run speed test for the current version
88        echo "./speed_cppad $test_name 123 $* > $build_dir/$out_file"
89        ./speed_cppad $test_name 123 $* > $out_file
90        #
91        echo_eval cd ../../..
92    fi
93done
94# compare the results
95echo "    one=cur, two=new"
96bin/speed_diff.sh \
97    $build_dir/cur.$option_list.out $build_dir/new.$option_list.out
98# ----------------------------------------------------------------------------
99echo "$0: OK"
100exit 0
101