gcc support

This commit is contained in:
gabime
2014-01-26 21:23:26 +02:00
parent 68504fa3e5
commit b093b82473
6 changed files with 70 additions and 29 deletions

27
include/stdafx.h Normal file
View File

@@ -0,0 +1,27 @@
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//
#pragma once
#ifdef _MSC_VER
#include "targetver.h"
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#endif
#include <string>
#include <chrono>
#include <ctime>
#include <memory>
#include <iostream>
#ifndef _MSC_VER
namespace std {
template<typename T, typename ...Args>
std::unique_ptr<T> make_unique( Args&& ...args )
{
return std::unique_ptr<T>( new T( std::forward<Args>(args)... ) );
}
}
#endif

58
include/utils.h Normal file
View File

@@ -0,0 +1,58 @@
#pragma once
#include <functional>
#include <chrono>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <locale>
namespace utils
{
template<typename T>
std::string format(const T& value)
{
static std::locale loc("");
std::stringstream ss;
ss.imbue(loc);
ss << value;
return ss.str();
}
inline void bench(const std::string& fn_name, const std::chrono::milliseconds &duration, const std::function<void() >& fn)
{
using namespace std::chrono;
typedef steady_clock the_clock;
size_t counter = 0;
seconds print_interval(1);
auto start_time = the_clock::now();
auto lastPrintTime = start_time;
while (true)
{
fn();
++counter;
auto now = the_clock::now();
if (now - start_time >= duration)
break;
auto p = now - lastPrintTime;
if (now - lastPrintTime >= print_interval)
{
std::cout << fn_name << ": " << format(counter) << " per sec" << std::endl;
counter = 0;
lastPrintTime = the_clock::now();
}
}
}
inline void bench(const std::string& fn_name, const std::function<void() >& fn)
{
using namespace std::chrono;
auto start = steady_clock::now();
fn();
auto delta = steady_clock::now() - start;
std::cout << fn_name << ": " << duration_cast<milliseconds>(delta).count() << " ms" << std::endl;
}
}