Przeglądaj źródła

added a test

master
rodzic
commit
065b937112
1 zmienionych plików z 50 dodań i 0 usunięć
  1. +50
    -0
      primary_operations_test.cpp

+ 50
- 0
primary_operations_test.cpp Wyświetl plik

@ -0,0 +1,50 @@
#include <chrono>
#include <iostream>
#include <string>
#include <functional>
using namespace std::chrono_literals;
template<class T>
void time_type(const size_t loop,T init,T incr ,const std::function<T(T,T)> lambda, std::string name)
{
T p;
auto begin = std::chrono::high_resolution_clock::now();
for(T i=0;i<loop;++i)
{
p=lambda(p,incr);
p=lambda(p,incr);
p=lambda(p,incr);
p=lambda(p,incr);
p=lambda(p,incr);
p=lambda(p,incr);
p=lambda(p,incr);
p=lambda(p,incr);
p=lambda(p,incr);
p=lambda(p,incr);
}
auto end = std::chrono::high_resolution_clock::now();
std::cout
<<name
<<" took "
<<std::chrono::duration_cast<std::chrono::microseconds>(end-begin).count()
<<"µs"
<<std::endl;
}
int main()
{
time_type<int>(10000,1,1,[](int a,int b)->int {return a+b;}, "int +");
time_type<int>(10000,20000,1,[](int a,int b)->int {return a-b;}, "int -");
time_type<int>(10000,1,2,[](int a,int b)->int {return a*b;}, "int *");
time_type<int>(10000,99999999,2,[](int a,int b)->int {return a/b;}, "int /");
time_type<float>(10000,1,0.5,[](float a,float b)->float {return a+b;}, "float +");
time_type<float>(10000,20000,1.14,[](float a,float b)->float {return a-b;}, "float -");
time_type<float>(10000,1,1.25,[](float a,float b)->float {return a*b;}, "float *");
time_type<float>(10000,99999999,1.25,[](float a,float b)->float {return a/b;}, "float /");
time_type<double>(10000,1,0.5,[](double a,double b)->double {return a+b;}, "double +");
time_type<double>(10000,20000,1.14,[](double a,double b)->double {return a-b;}, "double -");
time_type<double>(10000,1,1.25,[](double a,double b)->double {return a*b;}, "double *");
time_type<double>(10000,99999999,1.25,[](double a,double b)->double {return a/b;}, "double /");
}

Ładowanie…
Anuluj
Zapisz