CppNoddy  0.92
Loading...
Searching...
No Matches
SpeedVector.cpp
Go to the documentation of this file.
1/// \file DenseVector.cpp
2/// \ingroup Tests
3/// \ingroup Vector
4/// Some simple sanity checks for the NVector class
5/// with both double and complex types.
6
7#include <algorithm>
8
9#include <Types.h>
10#include <Timer.h>
11#include <Utility.h>
12#include "../Utils_Fill.h"
13
14using namespace CppNoddy;
15using namespace std;
16
17int main()
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}
int main()
Definition: SpeedVector.cpp:17
A spec for the CppNoddy Timer object.
A spec for a collection of utility functions.
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
A collection of OO numerical routines aimed at simple (typical) applied problems in continuum mechani...

© 2012

R.E. Hewitt