-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
556 additions
and
269 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,6 @@ | |
C++ Benchmark Library | ||
|
||
# Todo | ||
* Doxygen documentation | ||
* Port to Linux | ||
* Doxygen summary | ||
* Github documentation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Ignore everything in this directory | ||
* | ||
# Except this file | ||
!.gitignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
// | ||
// Created by Ivan Shynkarenka on 31.07.2015. | ||
// | ||
|
||
#ifdef _WIN32 | ||
#define _WIN32_WINNT 0x0601 | ||
#include <windows.h> | ||
#undef max | ||
#undef min | ||
#endif | ||
|
||
#ifdef __unix__ | ||
#include <time.h> | ||
#endif | ||
|
||
#include "macros.h" | ||
|
||
#include <limits> | ||
|
||
const int iterations = 10000000; | ||
|
||
BENCHMARK("std::chrono::high_resolution_clock::now", iterations) | ||
{ | ||
static auto timestamp = std::chrono::high_resolution_clock::now(); | ||
static int64_t resolution = std::numeric_limits<int64_t>::max(); | ||
|
||
auto current = std::chrono::high_resolution_clock::now(); | ||
int64_t duration = std::chrono::duration_cast<std::chrono::nanoseconds>(current - timestamp).count(); | ||
if ((duration > 0) && (duration < resolution)) { | ||
timestamp = current; | ||
resolution = duration; | ||
context.metrics().SetCustom("Resolution", (int)resolution); | ||
} | ||
} | ||
|
||
#ifdef _WIN32 | ||
BENCHMARK("GetTickCount", iterations) | ||
{ | ||
static DWORD timestamp = GetTickCount(); | ||
static int64_t resolution = std::numeric_limits<int64_t>::max(); | ||
|
||
DWORD current = GetTickCount(); | ||
int64_t duration = current - timestamp; | ||
if ((duration > 0) && (duration < resolution)) { | ||
timestamp = current; | ||
resolution = duration; | ||
context.metrics().SetCustom("Resolution", (int)(resolution * 1000 * 1000)); | ||
} | ||
} | ||
#endif | ||
|
||
#ifdef _WIN32 | ||
BENCHMARK("GetTickCount64", iterations) | ||
{ | ||
static ULONGLONG timestamp = GetTickCount64(); | ||
static int64_t resolution = std::numeric_limits<int64_t>::max(); | ||
|
||
ULONGLONG current = GetTickCount64(); | ||
int64_t duration = current - timestamp; | ||
if ((duration > 0) && (duration < resolution)) { | ||
timestamp = current; | ||
resolution = duration; | ||
context.metrics().SetCustom("Resolution", (int)(resolution * 1000 * 1000)); | ||
} | ||
} | ||
#endif | ||
|
||
#ifdef _WIN32 | ||
BENCHMARK("QueryPerformanceCounter", iterations) | ||
{ | ||
static LARGE_INTEGER timestamp{0}; | ||
static int64_t resolution = std::numeric_limits<int64_t>::max(); | ||
|
||
LARGE_INTEGER current; | ||
QueryPerformanceCounter(¤t); | ||
int64_t duration = current.QuadPart - timestamp.QuadPart; | ||
if ((duration > 0) && (duration < resolution)) { | ||
timestamp = current; | ||
resolution = duration; | ||
|
||
LARGE_INTEGER frequency; | ||
QueryPerformanceFrequency(&frequency); | ||
|
||
context.metrics().SetCustom("Resolution", (int)(resolution * 1000 * 1000 * 1000 / frequency.QuadPart)); | ||
} | ||
} | ||
#endif | ||
|
||
#ifdef __unix__ | ||
BENCHMARK("clock_gettime", iterations) | ||
{ | ||
static timespec timestamp{0}; | ||
static int64_t resolution = std::numeric_limits<int64_t>::max(); | ||
|
||
timespec current; | ||
clock_gettime(CLOCK_REALTIME, ¤t); | ||
int64_t duration = ((current.tv_sec - timestamp.tv_sec) * 1000 * 1000 * 1000) + (current.tv_nsec - timestamp.tv_nsec); | ||
if ((duration > 0) && (duration < resolution)) { | ||
timestamp = current; | ||
resolution = duration; | ||
context.metrics().SetCustom("Resolution", (int)resolution); | ||
|
||
timespec res; | ||
clock_getres(CLOCK_REALTIME, &res); | ||
context.metrics().SetCustom("Resolution (system)", (int)((res.tv_sec * 1000 * 1000 * 1000) + res.tv_nsec)); | ||
} | ||
} | ||
#endif | ||
|
||
BENCHMARK_MAIN() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.