1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
|
// $Id: speed_program.cpp 3788 2016-02-09 15:50:06Z bradbell $
/* --------------------------------------------------------------------------
CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-16 Bradley M. Bell
CppAD is distributed under multiple licenses. This distribution is under
the terms of the
GNU General Public License Version 3.
A copy of this license is included in the COPYING file of this distribution.
Please visit http://www.coin-or.org/CppAD/ for information on other licenses.
-------------------------------------------------------------------------- */
/*
$begin speed_program.cpp$$
$spell
speed_program.exe
cppad.hpp
Microsoft
namespace
std
const
cout
ctime
ifdef
const
endif
cpp
$$
$section Example Use of SpeedTest$$
$mindex test speed$$
$head Running This Program$$
On a Unix system that includes the $code g++$$ compiler,
you can compile and run this program by changing into the
$code speed/example$$ directory and executing the following commands
$codep
g++ -I../.. speed_program.cpp -o speed_program.exe
./speed_program.exe
$$
$head Program$$
$srccode%cpp% */
# include <cppad/utility/speed_test.hpp>
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 "double: c[*] = a[*] + b[*]";
}
int main(void)
{
CppAD::SpeedTest(Test, 10, 10, 100);
return 0;
}
/* %$$
$head Output$$
Executing of the program above generated the following output
(the rates will be different for each particular system):
$codep
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
$$
$end
*/
|