/******************************************************************************
Online C++ Compiler.
Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <iostream>
#include <random>
#include <limits>
#include <map>
#include <chrono>
#include <functional>
#define TIMES 1000000
double get_time ()
{
return std::chrono::duration <
double >(std::chrono::system_clock::now ().time_since_epoch ()).count ();
}
std::random_device dev;
std::mt19937 generator (dev());
std::default_random_engine _Generator;
bool _Init = false;
int number (int v1, int v2)
{
if (!_Init)
{
_Init = true;
_Generator.seed (dev ());
}
std::uniform_int_distribution < int >distribution (v1, v2);
return distribution (_Generator);
}
int random_drop (int min, int max)
{
std::uniform_int_distribution < int >distribution (min, max);
return distribution (generator);
}
double execution_time (std::function < int (int, int) > func)
{
auto now = get_time ();
for (int i = 0; i < TIMES; i++)
func (0, 500);
auto end = get_time ();
return end - now;
}
int main ()
{
std::cout << "number time : " << execution_time (number) << std::endl;
std::cout << "random_drop time : " << execution_time(random_drop) << std::endl;
}