CppNoddy  0.92
Loading...
Searching...
No Matches
Functions
SpeedVector.cpp File Reference
#include <algorithm>
#include <Types.h>
#include <Timer.h>
#include <Utility.h>
#include "../Utils_Fill.h"

Go to the source code of this file.

Functions

int main ()
 

Function Documentation

◆ main()

int main ( )

Definition at line 17 of file SpeedVector.cpp.

18{
19
20
21 const unsigned N = 250000000; // size of vectors
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
29 DenseVector<double> C( N, 0.0 );
30
31 Timer timer;
32 cout << "\n Filling a std::vector via [].\n";
33 timer.start();
34 for ( std::size_t i = 0; i < N; ++i ) {
35 A[i] = i;
36 }
37 timer.stop();
38 double timeSTL = timer.get_time();
39 timer.print();
40 timer.reset();
41
42 cout << "\n Filling a native array via [].\n";
43 timer.start();
44 for ( std::size_t i = 0; i < N; ++i ) {
45 B[i] = i;
46 }
47 timer.stop();
48 double timeNative = timer.get_time();
49 timer.print();
50 timer.reset();
51
52
53 cout << "\n Filling a DenseVector via [].\n";
54 timer.start();
55 for ( std::size_t i = 0; i < N; ++i ) {
56 C[i] = i;
57 }
58 timer.stop();
59 double timeDenseVec = timer.get_time();
60 timer.print();
61 timer.reset();
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.
Definition: DenseVector.h:34
A simple CPU-clock-tick timer for timing metods.
Definition: Timer.h:19
double get_time() const
Return the time.
Definition: Timer.cpp:34
void start()
Start the timer & reset stored time to zero.
Definition: Timer.cpp:12
void print() const
Write a string to cout stating the time taken.
Definition: Timer.cpp:59
void stop()
Stop the clock & add the current time interval to the previously stored values ready for printing.
Definition: Timer.cpp:17
void reset()
Pause the clock & add the time interval to the stored cumulative time.
Definition: Timer.cpp:26
double A(1.0)
initial hump amplitude

References CppNoddy::Timer::get_time(), CppNoddy::Timer::print(), CppNoddy::Timer::reset(), CppNoddy::Timer::start(), and CppNoddy::Timer::stop().

© 2012

R.E. Hewitt