<?xml version='1.0'?> <?xml-stylesheet type='text/xsl' href='pmathml.xsl'?> <html xmlns='http://www.w3.org/1999/xhtml'> <head> <title>speed_test: Example and test</title> <meta name="description" id="description" content="speed_test: Example and test"/> <meta name="keywords" id="keywords" content=" speed_test example test speed "/> <style type='text/css'> body { color : black } body { background-color : white } A:link { color : blue } A:visited { color : purple } A:active { color : purple } </style> <script type='text/javascript' language='JavaScript' src='_speed_test.cpp_xml.js'> </script> </head> <body> <table><tr> <td> <a href="http://www.coin-or.org/CppAD/" target="_top"><img border="0" src="_image.gif"/></a> </td> <td><a href="speed_test.xml" target="_top">Prev</a> </td><td><a href="speedtest.xml" target="_top">Next</a> </td><td> <select onchange='choose_across0(this)'> <option>Index-></option> <option>contents</option> <option>reference</option> <option>index</option> <option>search</option> <option>external</option> </select> </td> <td> <select onchange='choose_up0(this)'> <option>Up-></option> <option>CppAD</option> <option>library</option> <option>speed_test</option> <option>speed_test.cpp</option> </select> </td> <td> <select onchange='choose_down3(this)'> <option>CppAD-></option> <option>Install</option> <option>Introduction</option> <option>AD</option> <option>ADFun</option> <option>library</option> <option>Example</option> <option>configure</option> <option>Appendix</option> </select> </td> <td> <select onchange='choose_down2(this)'> <option>library-></option> <option>ErrorHandler</option> <option>NearEqual</option> <option>speed_test</option> <option>SpeedTest</option> <option>NumericType</option> <option>CheckNumericType</option> <option>SimpleVector</option> <option>CheckSimpleVector</option> <option>nan</option> <option>pow_int</option> <option>Poly</option> <option>LuDetAndSolve</option> <option>RombergOne</option> <option>RombergMul</option> <option>Runge45</option> <option>Rosen34</option> <option>OdeErrControl</option> <option>OdeGear</option> <option>OdeGearControl</option> <option>BenderQuad</option> <option>LuRatio</option> <option>std_math_unary</option> <option>CppAD_vector</option> <option>TrackNewDel</option> </select> </td> <td> <select onchange='choose_down1(this)'> <option>speed_test-></option> <option>speed_test.cpp</option> </select> </td> <td>speed_test.cpp</td> <td>Headings</td> </tr></table><br/> <center><b><big><big>speed_test: Example and test</big></big></b></center> <code><font color="blue"><pre style='display:inline'> # include <cppad/speed_test.hpp> # include <vector> namespace { // empty namespace void test(size_t size, size_t repeat) { // setup double *a = new double[size]; double *b = new double[size]; double *c = new double[size]; size_t i = size;; while(i) { --i; a[i] = i; b[i] = 2 * i; } // operations we are timing while(repeat--) { i = size;; while(i) { --i; c[i] = a[i] + b[i]; } } // teardown delete [] a; delete [] b; delete [] c; return; } } bool speed_test(void) { bool ok = true; // size of the test cases std::vector<size_t> size_vec(2); size_vec[0] = 10; size_vec[1] = 20; // use a small amout of time (we do not need accurate results) double time_min = .2; // run the test cases std::vector<size_t> rate_vec(2); rate_vec = CppAD::speed_test(test, size_vec, time_min); // time per repeat loop (note counting setup or teardown) double time_0 = 1. / double(rate_vec[0]); double time_1 = 1. / double(rate_vec[1]); // for this case, time should be linear w.r.t size double check = double(size_vec[1]) * time_0 / double(size_vec[0]); double rel_diff = std::abs(check - time_1) / time_1; ok &= (rel_diff <= .1); return ok; }</pre> </font></code> <hr/>Input File: speed/example/speed_test.cpp </body> </html>