MercuryDPM  0.11
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Vec3DSpeedTest.cpp File Reference
#include <iostream>
#include "Math/Vector.h"
#include "Math/Matrix.h"
#include "MercuryTime.h"

Go to the source code of this file.

Functions

Mdouble passByReference (Vec3D &v)
 
Mdouble passByConstReference (const Vec3D &v)
 
Mdouble passByPointer (Vec3D *v)
 
Mdouble passByValue (Vec3D v)
 
Mdouble passByReference (Matrix3D &v)
 
Mdouble passByConstReference (const Matrix3D &v)
 
Mdouble passByPointer (Matrix3D *v)
 
Mdouble passByValue (Matrix3D v)
 
void testVec3D (unsigned int n)
 
void testMatrix3D (unsigned int n)
 
int main ()
 

Function Documentation

int main ( )

Definition at line 151 of file Vec3DSpeedTest.cpp.

References testMatrix3D(), and testVec3D().

152 {
153  unsigned int n = 1e8;
154  testVec3D(n);
155  testMatrix3D(n);
156  return 0;
157 }
void testVec3D(unsigned int n)
void testMatrix3D(unsigned int n)
Mdouble passByConstReference ( const Vec3D v)

Definition at line 38 of file Vec3DSpeedTest.cpp.

References Vec3D::X.

Referenced by testMatrix3D(), and testVec3D().

39 {
40  return v.X;
41 }
Mdouble X
the vector components
Definition: Vector.h:52
Mdouble passByConstReference ( const Matrix3D v)

Definition at line 58 of file Vec3DSpeedTest.cpp.

References Matrix3D::XX.

59 {
60  return v.XX;
61 }
Mdouble XX
all nine matrix elements
Definition: Matrix.h:42
Mdouble passByPointer ( Vec3D v)

Definition at line 43 of file Vec3DSpeedTest.cpp.

References Vec3D::X.

Referenced by testMatrix3D(), and testVec3D().

44 {
45  return v->X;
46 }
Mdouble X
the vector components
Definition: Vector.h:52
Mdouble passByPointer ( Matrix3D v)

Definition at line 63 of file Vec3DSpeedTest.cpp.

References Matrix3D::XX.

64 {
65  return v->XX;
66 }
Mdouble XX
all nine matrix elements
Definition: Matrix.h:42
Mdouble passByReference ( Vec3D v)

Definition at line 33 of file Vec3DSpeedTest.cpp.

References Vec3D::X.

Referenced by testMatrix3D(), and testVec3D().

34 {
35  return v.X;
36 }
Mdouble X
the vector components
Definition: Vector.h:52
Mdouble passByReference ( Matrix3D v)

Definition at line 53 of file Vec3DSpeedTest.cpp.

References Matrix3D::XX.

54 {
55  return v.XX;
56 }
Mdouble XX
all nine matrix elements
Definition: Matrix.h:42
Mdouble passByValue ( Vec3D  v)

Definition at line 48 of file Vec3DSpeedTest.cpp.

References Vec3D::X.

Referenced by testMatrix3D(), and testVec3D().

49 {
50  return v.X;
51 }
Mdouble X
the vector components
Definition: Vector.h:52
Mdouble passByValue ( Matrix3D  v)

Definition at line 68 of file Vec3DSpeedTest.cpp.

References Matrix3D::XX.

69 {
70  return v.XX;
71 }
Mdouble XX
all nine matrix elements
Definition: Matrix.h:42
void testMatrix3D ( unsigned int  n)

Definition at line 112 of file Vec3DSpeedTest.cpp.

References passByConstReference(), passByPointer(), passByReference(), passByValue(), Time::tic(), and Time::toc().

Referenced by main().

113 {
114  std::cout << "testing Matrix3D performance" << std::endl;
115 
116  Matrix3D v={1,0,0,0,0,0,0,0,0};
117  Mdouble x=0;
118 
119  Time time;
120  time.tic();
121  for (unsigned int i = 0; i < n; i++)
122  {
123  x+=passByReference(v);
124  }
125  std::cout << "passByReference clocks: " << time.toc()*CLOCKS_PER_SEC << std::endl;
126 
127  time.tic();
128  for (unsigned int i = 0; i < n; i++)
129  {
130  x+=passByConstReference(v);
131  }
132  std::cout << "passByConstReference clocks: " << time.toc()*CLOCKS_PER_SEC << std::endl;
133 
134  Matrix3D* p = &v;
135  time.tic();
136  for (unsigned int i = 0; i < n; i++)
137  {
138  x+=passByPointer(p);
139  }
140  std::cout << "passByPointer clocks: " << time.toc()*CLOCKS_PER_SEC << std::endl;
141 
142  time.tic();
143  for (unsigned int i = 0; i < n; i++)
144  {
145  x+=passByValue(v);
146  }
147  std::cout << "passByValue clocks: " << time.toc()*CLOCKS_PER_SEC << std::endl;
148  std::cout << x << std::endl;
149 }
Mdouble passByConstReference(const Vec3D &v)
Mdouble passByPointer(Vec3D *v)
Allows for timing the algorithms; accurate up to 0.01 sec.
Definition: MercuryTime.h:40
double Mdouble
Mdouble passByValue(Vec3D v)
void tic()
This is like a start button of a stopwatch. Assigns the variable start with the current number of clo...
Definition: MercuryTime.h:48
Mdouble passByReference(Vec3D &v)
Mdouble toc()
This is like a stop button of a stopwatch. Assigns the variable finish to the current value of ticks ...
Definition: MercuryTime.h:58
Implementation of a 3D matrix.
Definition: Matrix.h:36
void testVec3D ( unsigned int  n)

Definition at line 73 of file Vec3DSpeedTest.cpp.

References passByConstReference(), passByPointer(), passByReference(), passByValue(), Time::tic(), and Time::toc().

Referenced by main().

74 {
75  std::cout << "testing Vec3D performance" << std::endl;
76 
77  Vec3D v={1,0,0};
78  Mdouble x=0;
79 
80  Time time;
81  time.tic();
82  for (unsigned int i = 0; i < n; i++)
83  {
84  x+=passByReference(v);
85  }
86  std::cout << "passByReference clocks: " << time.toc()*CLOCKS_PER_SEC << std::endl;
87 
88  time.tic();
89  for (unsigned int i = 0; i < n; i++)
90  {
92  }
93  std::cout << "passByConstReference clocks: " << time.toc()*CLOCKS_PER_SEC << std::endl;
94 
95  Vec3D* p = &v;
96  time.tic();
97  for (unsigned int i = 0; i < n; i++)
98  {
99  x+=passByPointer(p);
100  }
101  std::cout << "passByPointer clocks: " << time.toc()*CLOCKS_PER_SEC << std::endl;
102 
103  time.tic();
104  for (unsigned int i = 0; i < n; i++)
105  {
106  x+=passByValue(v);
107  }
108  std::cout << "passByValue clocks: " << time.toc()*CLOCKS_PER_SEC << std::endl;
109  std::cout << x << std::endl;
110 }
Mdouble passByConstReference(const Vec3D &v)
Mdouble passByPointer(Vec3D *v)
Allows for timing the algorithms; accurate up to 0.01 sec.
Definition: MercuryTime.h:40
double Mdouble
Mdouble passByValue(Vec3D v)
void tic()
This is like a start button of a stopwatch. Assigns the variable start with the current number of clo...
Definition: MercuryTime.h:48
Mdouble passByReference(Vec3D &v)
Mdouble toc()
This is like a stop button of a stopwatch. Assigns the variable finish to the current value of ticks ...
Definition: MercuryTime.h:58
Implementation of a 3D vector (by Vitaliy).
Definition: Vector.h:45