Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "vectorclass.h"
- #include "ranvec1.h"
- #include <chrono>
- #include <random>
- #include <iostream>
- using namespace std;
- constexpr int M = 20000000;
- class stoper
- {
- chrono::time_point<chrono::high_resolution_clock> a,b;
- public:
- void start(){a = chrono::high_resolution_clock::now();}
- void stop() {b = chrono::high_resolution_clock::now();}
- double value()
- {
- chrono::duration<double> elapsed_seconds = b-a;
- return elapsed_seconds.count();
- }
- void show()
- {
- cout << value()<<" ";
- }
- };
- int main()
- {
- for (int k=0;k<5;k++)
- {
- int seed = k;
- Ranvec1 ran(3);
- ran.init(seed);
- stoper st;
- float sum1=0.0;
- st.start();
- Vec8f rf;
- for (int i=0;i<M/8;i++){
- rf = ran.random8f();
- for (int j=0;j<8;j++)
- sum1+=rf[i];
- }
- st.stop();
- st.show();
- random_device rd;
- mt19937 gen{rd()};
- uniform_real_distribution<float> dist;
- float sum2=0.0;
- st.start();
- for (int i=0;i<M;i++){
- sum2+= dist(gen);
- }
- st.stop();
- st.show();
- cout<<endl<<sum1/M<<" "<<sum2/M<<endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement