-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbenchmarking.cpp
More file actions
162 lines (115 loc) · 4.77 KB
/
benchmarking.cpp
File metadata and controls
162 lines (115 loc) · 4.77 KB
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/*
* benchmarking.cpp
*
* Created on: Jul 17, 2014
* Author: tchr
*/
#include <iostream>
#include <time.h>
#include <stdint.h>
#include <ctime>
#include <boost/random.hpp>
#include <boost/generator_iterator.hpp>
#include <boost/random/gamma_distribution.hpp>
#include <boost/random/uniform_int_distribution.hpp>
#include "randn.h"
#include "permutations.h"
using namespace std;
double benchmarking() {
//double a=0.0;
double a=0;
uint8_t i,j,k,l;
cout<<"\nBenchmarking one core - please wait...\n";
clock_t t1,t2;
// Adding numbers
t1=clock();
/*
One thing that can slow any loop, and often does:
The post- increment/decrement, when a pre- increment/decrement will do the job.
The post- version requires an anonymous variable be created, while the pre- version does not.
*/
for(i=125;i!=0;--i){
for(j=200;j!=0;--j){
for(k=200;k!=0;--k){
for(l=200;l!=0;--l){
a+=0.01;
}}}}
t2=clock();
cout<<"\nAdded 1 billion numbers in "<<(float)(1.0*(t2-t1)/(1.0*CLOCKS_PER_SEC))<<" seconds.\n";
//Creating Permutations
vector <int> p;
t1=clock();
for ( long counter = 1000000; counter!=0; --counter ) {
permutation(16,p);
p.clear();
}
t2=clock();
cout<<"\n1 Million Permutations of 16 numbers in "<<(float)(1.0*(t2-t1)/(1.0*CLOCKS_PER_SEC))<<" seconds.\n";
//------------------------------------------------------------------------
// Random Distributions
//------------------------------------------------------------------------
int n=10;
cout<<"\nCreating "<<n<<" million random numbers of several Distributions";
double g;
// Creating Normal Distributed random numbers ("Polar" version without trigonometric calls)
g=0;
t1=clock();
for ( long counter = n*1000000; counter!=0; --counter ) g+=randn_notrig();
t2=clock();
cout<<"\n\t(Normal Distr. Notrig) in "<<(float)(1.0*(t2-t1)/(1.0*CLOCKS_PER_SEC))<<" seconds.";
//cout<<endl;for ( long counter = 6; counter!=0; --counter ) cout<<randn_notrig()<<" ";
// Creating Normal Distributed random numbers (Standard version with trigonometric calls)
g=0;
t1=clock();
for ( long counter = n*1000000; counter!=0; --counter ) g+=randn_trig();
t2=clock();
cout<<"\n\t(Normal Distr. Trig) in "<<(float)(1.0*(t2-t1)/(1.0*CLOCKS_PER_SEC))<<" seconds.";
//cout<<endl;for ( long counter = 6; counter!=0; --counter ) cout<<randn_trig()<<" ";
// Boost Libraries
typedef boost::mt11213b RNGType;
RNGType rng;
//------------------------
// Creating Normal Distribution numbers (Boost)
g=0;
boost::random::normal_distribution<> norm(0,1);
boost::variate_generator< RNGType, boost::random::normal_distribution<> >
normal(rng, norm);
t1=clock();
for ( long counter = n*1000000; counter!=0; --counter ) g+=normal();
t2=clock();
cout<<"\n\t(Normal Distr. (Boost)) in "<<(float)(1.0*(t2-t1)/(1.0*CLOCKS_PER_SEC))<<" seconds.";
//cout<<endl;for ( long counter = 6; counter!=0; --counter ) cout<<normal()<<" ";
// Creating Gamma Distribution numbers (Boost)
g=0;
boost::random::gamma_distribution<> gamma(1,1);
boost::variate_generator< RNGType, boost::random::gamma_distribution<> >
gammanum(rng, gamma);
t1=clock();
for ( long counter = n*1000000; counter!=0; --counter ) g+=gammanum();
t2=clock();
cout<<"\n\t(Gamma Distr. (Boost)) in "<<(float)(1.0*(t2-t1)/(1.0*CLOCKS_PER_SEC))<<" seconds.";
//cout<<endl;for ( long counter = 6; counter!=0; --counter ) cout<<gammanum()<<" ";
// Creating Uniform Distribution integer numbers (Boost)
g=0;
boost::random::uniform_int_distribution<> unif(1, 6);
t1=clock();
for ( long counter = n*1000000; counter!=0; --counter ) g+=unif(rng);
t2=clock();
cout<<"\n\t(Unif.Distr. (Boost)) in "<<(float)(1.0*(t2-t1)/(1.0*CLOCKS_PER_SEC))<<" seconds.";
//cout<<endl;for ( long counter = 20; counter!=0; --counter ) cout<<unif(rng)<<" ";
// Creating Poisson Distribution numbers (Boost)
g=0;
boost::random::poisson_distribution<> pois(10);
t1=clock();
for ( long counter = n*1000000; counter!=0; --counter ) g+=pois(rng);
t2=clock();
cout<<"\n\t(Poisson Distr. (Boost)) in "<<(float)(1.0*(t2-t1)/(1.0*CLOCKS_PER_SEC))<<" seconds.";
//cout<<endl;for ( long counter = 20; counter!=0; --counter ) cout<<pois(rng)<<" ";
// -------------------------------------------------------------------------------------------
cout<<"\n\nRunning a typical simulation with required characteristics to estimate which functions and parameters to use during execution time. This waiting time will be rewarded due to minimal total time execution.\n";
cout<<"Additionally you will be informed with good accuracy about the estimated remaining time for your simulations.\n";
cout<<"--------------------------------------------------------------------------------\n";
return a;
};
// Validity Check
// Simulations Benchmark