Changeset 2494


Ignore:
Timestamp:
Oct 4, 2012 12:06:19 PM (7 years ago)
Author:
bradbell
Message:

time_test.hpp: include case where test has a size argument.
main.cpp: more precision in results that are < 1000, more feeback during execution.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/cppad/time_test.hpp

    r2215 r2494  
    44
    55/* --------------------------------------------------------------------------
    6 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-11 Bradley M. Bell
     6CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-12 Bradley M. Bell
    77
    88CppAD is distributed under multiple licenses. This distribution is under
     
    4242%$$
    4343$icode%time% = time_test(%test%, %time_min%)%$$
     44$icode%time% = time_test(%test%, %time_min%, %test_size%)%$$
    4445
    4546$head Purpose$$
     
    7071$head test$$
    7172The $code time_test$$ argument $icode test$$ is a function,
    72 or function object, that supports the syntax
     73or function object.
     74In the case where $icode test_size$$ is not present,
     75$icode test$$ supports the syntax
    7376$codei%
    7477        %test%(%repeat%)
    7578%$$
    76 and its return value is $code void$$.
     79In the case where $icode test_size$$ is present,
     80$icode test$$ supports the syntax
     81$codei%
     82        %test%(%size%, %repeat%)
     83%$$
     84In either case, the return value for $icode test$$ is $code void$$.
     85
     86$subhead size$$
     87If the argument $icode size$$ is present,
     88it has prototype
     89$codei%
     90        size_t %size%
     91%$$
     92and is equal to the $icode test_size$$ argument to $code time_test$$.
    7793
    7894$subhead repeat$$
     
    8197        size_t %repeat%
    8298%$$
    83 It specifies the number of times to repeat the test.
     99It will be equal to the $icode size$$ argument to $code time_test$$.
    84100
    85101$head time_min$$
     
    92108The $icode repeat$$ argument to $icode test$$ is increased
    93109until this amount of execution time (or more) is reached.
     110
     111$head test_size$$
     112This argument has prototype
     113$codei%
     114        size_t %test_size%
     115%$$
     116It specifies the $icode size$$ argument to $icode test$$.
    94117
    95118$head time$$
     
    160183}
    161184
     185/*!
     186Preform one wall clock execution timing test.
     187
     188\tparam Test
     189Either the type <code>void (*)(size_t, size_t)</code> or a function object
     190type that supports the same syntax.
     191
     192\param test
     193The function, or function object, that supports the operation
     194<code>test(size, repeat)</code> where
     195\c is the size for this test and
     196\c repeat is the number of times
     197to repeat the tests operaiton that is being timed.
     198
     199\param time_min
     200is the minimum amount of time that \c test should take to preform
     201the repetitions of the operation being timed.
     202
     203\param test_size
     204will be used for the value of \c size in the call to \c test.
     205*/
     206template <class Test>
     207double time_test(Test test, double time_min, size_t test_size)
     208{
     209        size_t repeat = 0;
     210        double s0     = elapsed_seconds();
     211        double s1     = s0;
     212        while( s1 - s0 < time_min )
     213        {       repeat = std::max(size_t(1), 2 * repeat);
     214                s0     = elapsed_seconds();
     215                test(test_size, repeat);
     216                s1     = elapsed_seconds();
     217        }
     218        double time = (s1 - s0) / double(repeat);
     219        return time;
     220}
     221
    162222CPPAD_END_NAMESPACE
    163223
  • trunk/omh/whats_new_12.omh

    r2492 r2494  
    6161assist you in learning about changes between various versions of CppAD.
    6262
     63$head 10-04$$
     64$list number$$
     65Change $cref speed_main$$ so that it outputs small rates (less than 1000)
     66with two decimal points of precision (instead of as integers).
     67In addition, flush result for each size when it finishes to give user
     68more feedback about how things are progressing.
     69$lnext
     70Add the optional $cref/test_size/time_test/test_size/$$ argument
     71to the $code time_test$$ routine.
     72$lend
     73
    6374$head 10-03$$
    6475Change the $code hold_memory$$ speed to option to just
  • trunk/speed/main.cpp

    r2493 r2494  
    1616# include <cstddef>
    1717# include <iostream>
     18# include <iomanip>
    1819# include <cppad/vector.hpp>
    1920# include <cppad/speed/det_grad_33.hpp>
    2021# include <cppad/speed/det_33.hpp>
    21 # include <cppad/speed_test.hpp>
     22# include <cppad/time_test.hpp>
    2223# include <cppad/speed/uniform_01.hpp>
    2324# include <cppad/poly.hpp>
     
    314315        bool run_correct(bool correct_case(bool), const char *case_name)
    315316        {       bool ok;
     317# ifdef SPEED_DOUBLE
     318                ok = correct_case(true);
     319# else
     320                ok = correct_case(false);
     321# endif
    316322                cout << AD_PACKAGE << "_" << case_name;
    317323                if( global_retape )
     
    324330                        cout << "_memory";
    325331                cout << "_ok = ";
    326 # ifdef SPEED_DOUBLE
    327                 ok = correct_case(true);
    328 # else
    329                 ok = correct_case(false);
    330 # endif
    331332                if( ok )
    332333                {       cout << " true" << endl;
     
    349350                output(size_vec);
    350351                cout << endl;
    351 
    352                 CppAD::vector<size_t> rate_vec( size_vec.size() );
    353                 rate_vec = CppAD::speed_test(speed_case, size_vec, time_min);
    354352                cout << AD_PACKAGE << "_" << case_name;
    355353                if( global_retape )
     
    362360                        cout << "_memory";
    363361                cout << "_rate = ";
    364                 output(rate_vec);
    365                 cout << endl;
     362
     363                cout << std::fixed;
     364                for(size_t i = 0; i < size_vec.size(); i++)
     365                {       if( i == 0 )
     366                                cout << "[ ";
     367                        else    cout << ", ";   
     368                        cout << std::flush;
     369                        size_t size = size_vec[i];
     370                        double time = CppAD::time_test(speed_case, time_min, size);
     371                        double rate = 1. / time;
     372                        if( rate >= 1000 )
     373                                cout << std::setprecision(0) << rate;
     374                        else cout << std::setprecision(2) << rate;
     375                }
     376                cout << " ]" << endl;
    366377                return;
    367378        }
Note: See TracChangeset for help on using the changeset viewer.