Small tests i share because why not
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

56 lines
2.4 KiB

#include <chrono>
#include <iostream>
#include <string>
#include <functional>
#include "9float.hpp"
using namespace std::chrono_literals;
template<class T>
void time_type(const 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+=1)
{
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 /");
time_type<ninefloat::Q<int,16>>(10000,1,0.5,[](ninefloat::Q<int,16> a,ninefloat::Q<int,16> b)->ninefloat::Q<int,16> {return a+b;}, "ninefloat::Q<int,16> +");
time_type<ninefloat::Q<int,16>>(10000,20000,1.14,[](ninefloat::Q<int,16> a,ninefloat::Q<int,16> b)->ninefloat::Q<int,16> {return a-b;}, "ninefloat::Q<int,16> -");
time_type<ninefloat::Q<int,16>>(10000,1,1.25,[](ninefloat::Q<int,16> a,ninefloat::Q<int,16> b)->ninefloat::Q<int,16> {return a*b;}, "ninefloat::Q<int,16> *");
time_type<ninefloat::Q<int,16>>(10000,99999999,1.25,[](ninefloat::Q<int,16> a,ninefloat::Q<int,16> b)->ninefloat::Q<int,16> {return a/b;}, "ninefloat::Q<int,16> /");
}