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

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

speed_program.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>Example Use of SpeedTest</title>
<meta http-equiv='Content-Type' content='text/html' charset='utf-8'/>
<meta name="description" id="description" content="Example Use of SpeedTest"/>
<meta name="keywords" id="keywords" content=" Speedtest example test speed use of speedtest running this program output "/>
<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_program.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="speedtest.xml" target="_top">Prev</a>
</td><td><a href="time_test.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>SpeedTest</option>
<option>speed_program.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>SpeedTest-&gt;</option>
<option>speed_program.cpp</option>
</select>
</td>
<td>speed_program.cpp</td>
<td>
<select onchange='choose_current0(this)'>
<option>Headings-&gt;</option>
<option>Running This Program</option>
<option>Program</option>
<option>Output</option>
</select>
</td>
</tr></table><br/>







<center><b><big><big>Example Use of SpeedTest</big></big></b></center>
<br/>
<b><big><a name="Running This Program" id="Running This Program">Running This Program</a></big></b>
<br/>
On a Unix system that includes the <code><font color="blue">g++</font></code> compiler,
you can compile and run this program by changing into the
<code><font color="blue">speed/example</font></code> directory and executing the following commands
<code><font color='blue'><pre style='display:inline'> 
	g++ -I../.. speed_program.cpp -o speed_program.exe
	./speed_program.exe
</pre></font></code>


<br/>
<br/>
<b><big><a name="Program" id="Program">Program</a></big></b>

<code><font color='blue'><pre style='display:inline'> 
# include &lt;cppad/speed_test.hpp&gt;

std::string 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 a test name that is valid for all sizes and repeats
	return &quot;double: c[*] = a[*] + b[*]&quot;;
}
int main(void)
{
	CppAD::SpeedTest(Test, 10, 10, 100);
	return 0;
}

</pre></font></code>


<br/>
<br/>
<b><big><a name="Output" id="Output">Output</a></big></b>
<br/>
Executing of the program above generated the following output 
(the rates will be different for each particular system):
<code><font color='blue'><pre style='display:inline'> 
	double: c[*] = a[*] + b[*]
	size = 10  rate = 14,122,236
	size = 20  rate = 7,157,515
	size = 30  rate = 4,972,500
	size = 40  rate = 3,887,214
	size = 50  rate = 3,123,086
	size = 60  rate = 2,685,214
	size = 70  rate = 2,314,737
	size = 80  rate = 2,032,124
	size = 90  rate = 1,814,145
	size = 100 rate = 1,657,828
</pre></font></code>



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

</body>
</html>