Codebase list cppad / upstream/2015.00.00.7 doc / speed_test.cpp.xml
upstream/2015.00.00.7

Tree @upstream/2015.00.00.7 (Download .tar.gz)

speed_test.cpp.xml @upstream/2015.00.00.7raw · history · blame

<?xml version='1.0'?>
<html xmlns='http://www.w3.org/1999/xhtml'
      xmlns:math='http://www.w3.org/1998/Math/MathML'
>
<head>
<title>speed_test: Example and test</title>
<meta http-equiv='Content-Type' content='text/html' charset='utf-8'/>
<meta name="description" id="description" content="speed_test: Example and test"/>
<meta name="keywords" id="keywords" content=" speed_test example test speed speed_test: and "/>
<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-&gt;</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-&gt;</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-&gt;</option>
<option>Install</option>
<option>Introduction</option>
<option>AD</option>
<option>ADFun</option>
<option>preprocessor</option>
<option>multi_thread</option>
<option>library</option>
<option>ipopt_solve</option>
<option>Example</option>
<option>speed</option>
<option>Appendix</option>
</select>
</td>
<td>
<select onchange='choose_down2(this)'>
<option>library-&gt;</option>
<option>ErrorHandler</option>
<option>NearEqual</option>
<option>speed_test</option>
<option>SpeedTest</option>
<option>time_test</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>CppAD_vector</option>
<option>thread_alloc</option>
<option>index_sort</option>
<option>BenderQuad</option>
<option>opt_val_hes</option>
<option>LuRatio</option>
</select>
</td>
<td>
<select onchange='choose_down1(this)'>
<option>speed_test-&gt;</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 &lt;cppad/speed_test.hpp&gt;
# include &lt;cppad/vector.hpp&gt;

namespace { // empty namespace
	using CppAD::vector;
	vector&lt;double&gt; a, b, c;
	void test(size_t size, size_t repeat)
	{	// setup
		a.resize(size);
		b.resize(size);
		c.resize(size);
		size_t i  = size;;
		while(i)
		{	--i;
			a[i] = i;
			b[i] = 2 * i;
			c[i] = 0.0;
		}
		// operations we are timing
		while(repeat--)
		{	i = size;;
			while(i)
			{	--i;
				c[i] += std::sqrt(a[i] * a[i] + b[i] * b[i]);
			}
		}
	}
}
bool speed_test(void)
{	bool ok = true;

	// size of the test cases
	vector&lt;size_t&gt; size_vec(2);
	size_vec[0] = 40;
	size_vec[1] = 80;

	// minimum amount of time to run test
	double time_min = 0.5;

	// run the test cases
	vector&lt;size_t&gt; 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 = (check - time_1) / time_1;
	ok             &amp;= (std::fabs(rel_diff) &lt;= .1);
	if( ! ok )
		std::cout &lt;&lt; std::endl &lt;&lt; &quot;rel_diff = &quot; &lt;&lt; rel_diff &lt;&lt; std::endl;
 
	a.clear();
	b.clear();
	c.clear();
	return ok;
}
</pre>

</font></code>


<hr/>Input File: speed/example/speed_test.cpp

</body>
</html>