Functional NegBin implementaion
This commit is contained in:
commit
82c2bb9f1b
9 changed files with 332 additions and 0 deletions
68
NegBin/NegBinBenchmark.cpp
Normal file
68
NegBin/NegBinBenchmark.cpp
Normal file
|
@ -0,0 +1,68 @@
|
|||
//
|
||||
// Created by trotfunky on 06/11/2020.
|
||||
//
|
||||
|
||||
#include <iostream>
|
||||
#include <chrono>
|
||||
#include <random>
|
||||
#include "NegBin.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
std::random_device rd;
|
||||
std::default_random_engine gen(rd());
|
||||
|
||||
std::uniform_int_distribution<> distribution(0,2147483647);
|
||||
|
||||
std::vector<NegBin> randoms1;
|
||||
std::vector<NegBin> randoms2;
|
||||
randoms1.reserve(1000000);
|
||||
randoms2.reserve(1000000);
|
||||
|
||||
for (int i = 0;i<1000000;i++)
|
||||
{
|
||||
randoms1.emplace_back(longBitField(distribution(gen)));
|
||||
randoms2.emplace_back(longBitField(distribution(gen)));
|
||||
}
|
||||
|
||||
NegBin temp;
|
||||
|
||||
auto start = std::chrono::high_resolution_clock::now();
|
||||
for (int i = 0;i<1000000;i++)
|
||||
{
|
||||
temp = randoms1.at(i) + randoms2.at(i);
|
||||
}
|
||||
auto end = std::chrono::high_resolution_clock::now();
|
||||
|
||||
auto total_duration = std::chrono::duration_cast<std::chrono::nanoseconds>(end-start);
|
||||
|
||||
std::cout << "Total time taken for 1 000 000 iterations is :" << total_duration.count()/1000 << "µs" << std::endl;
|
||||
std::cout << "Time per addition is roughly : " << total_duration.count()/1000000 << "ns" << std::endl;
|
||||
|
||||
std::vector<long> randomsInts1;
|
||||
std::vector<long> randomsInts2;
|
||||
randomsInts1.reserve(1000000);
|
||||
randomsInts2.reserve(1000000);
|
||||
|
||||
for (int i = 0;i<1000000;i++)
|
||||
{
|
||||
randomsInts1.push_back(distribution(gen));
|
||||
randomsInts2.push_back(distribution(gen));
|
||||
}
|
||||
|
||||
long tempInt;
|
||||
|
||||
auto startInts = std::chrono::high_resolution_clock::now();
|
||||
for (int i = 0;i<1000000;i++)
|
||||
{
|
||||
tempInt = randomsInts1.at(i) * randomsInts2.at(i);
|
||||
}
|
||||
auto endInts = std::chrono::high_resolution_clock::now();
|
||||
|
||||
auto total_int_duration = std::chrono::duration_cast<std::chrono::nanoseconds>(endInts-startInts);
|
||||
|
||||
std::cout << "Total time taken for 1 000 000 iterations is :" << total_int_duration.count()/1000 << "µs" << std::endl;
|
||||
std::cout << "Time per addition is roughly : " << total_int_duration.count()/1000000 << "ns" << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue