18{
19
20
21 const unsigned N = 250000000;
22 cout << " Using vectors of size " << N << " \n";
23
24 std::vector<double>
A( N, 0.0 );
25
26 double* B;
27 B = new double[ N ];
28
30
32 cout << "\n Filling a std::vector via [].\n";
34 for ( std::size_t i = 0; i < N; ++i ) {
36 }
41
42 cout << "\n Filling a native array via [].\n";
44 for ( std::size_t i = 0; i < N; ++i ) {
45 B[i] = i;
46 }
48 double timeNative = timer.
get_time();
51
52
53 cout << "\n Filling a DenseVector via [].\n";
55 for ( std::size_t i = 0; i < N; ++i ) {
56 C[i] = i;
57 }
59 double timeDenseVec = timer.
get_time();
62
63 cout << "\nDenseVector slow down is " << 100*(timeDenseVec-timeNative)/timeNative << "\n";
64 cout << "STL:vector slow down is " << 100*(timeSTL-timeNative)/timeNative << "\n";
65}
An DenseVector class – a dense vector object.
A simple CPU-clock-tick timer for timing metods.
double get_time() const
Return the time.
void start()
Start the timer & reset stored time to zero.
void print() const
Write a string to cout stating the time taken.
void stop()
Stop the clock & add the current time interval to the previously stored values ready for printing.
void reset()
Pause the clock & add the time interval to the stored cumulative time.
double A(1.0)
initial hump amplitude