Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial implementation of Benchmark project
Benchmarks are going to be more important as attention shifts to the overall performance capabilities of Autowiring. Re-enable this project, add a few additional benchmarks, and also make it possible to run specific benchmarks in isolation.
- Loading branch information
1 parent
64e4d0b
commit cd8072f
Showing
14 changed files
with
516 additions
and
199 deletions.
There are no files selected for viewing
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,83 @@ | ||
// Copyright (C) 2012-2015 Leap Motion, Inc. All rights reserved. | ||
#include "stdafx.h" | ||
#include "Benchmark.h" | ||
#include "ContextSearchBm.h" | ||
#include "DispatchQueueBm.h" | ||
#include "PrintableDuration.h" | ||
#include "PriorityBoost.h" | ||
#include <map> | ||
#include <iomanip> | ||
#include <iostream> | ||
#include <string> | ||
|
||
Benchmark PrintUsage(void); | ||
|
||
struct Entry { | ||
const char* name = nullptr; | ||
const char* desc = nullptr; | ||
Benchmark(*pfn)() = nullptr; | ||
}; | ||
|
||
std::pair<std::string, Entry> MakeEntry(const char* name, const char* desc, Benchmark(*pfn)()) { | ||
Entry retVal; | ||
retVal.name = name; | ||
retVal.desc = desc; | ||
retVal.pfn = pfn; | ||
return std::make_pair(name, retVal); | ||
} | ||
|
||
static std::map<std::string, Entry> sc_commands = { | ||
MakeEntry("help", "Displays this information", &PrintUsage), | ||
MakeEntry("priority", "Thread priority boost behavior", &PriorityBoost::CanBoostPriority), | ||
MakeEntry("search", "Autowiring context search cost", &ContextSearchBm::Search), | ||
MakeEntry("cache", "Autowiring cache behavior", &ContextSearchBm::Cache), | ||
MakeEntry("fast", "Autowired versus AutowiredFast", &ContextSearchBm::Fast), | ||
MakeEntry("dispatch", "Dispatch queue execution rate", &DispatchQueueBm::Dispatch) | ||
}; | ||
|
||
Benchmark PrintUsage(void) { | ||
std::cout | ||
<< "Usage: AutoBench <command>" << std::endl | ||
<< "Supported commands:" << std::endl | ||
<< std::endl; | ||
|
||
for (auto& command : sc_commands) | ||
std::cout << " " << std::setw(12) << std::left << command.first << command.second.desc << std::endl; | ||
return Benchmark{}; | ||
} | ||
|
||
int main(int argc, const char* argv[]) { | ||
switch (argc) { | ||
default: | ||
PrintUsage(); | ||
return -1; | ||
case 2: | ||
auto& cur = sc_commands[argv[1]]; | ||
if (!cur.name) { | ||
std::cerr << "Unrecognized command" << std::endl; | ||
PrintUsage(); | ||
return -1; | ||
} | ||
|
||
try { | ||
auto benchmark = cur.pfn(); | ||
|
||
// Need a base duration to print all values against--the base duration is always the first entry | ||
std::chrono::duration<double> base; | ||
if (!benchmark.entries.empty()) | ||
base = benchmark.entries[0].duration; | ||
|
||
for (auto& entry : benchmark.entries) | ||
std::cout | ||
<< std::setw(40) << std::left << entry.name | ||
<< std::setw(7) << PrintableDuration(entry.duration) | ||
<< " " << std::fixed << std::setprecision(2) << (100 * entry.duration.count() / base.count()) << "%" | ||
<< std::endl; | ||
} | ||
catch (std::exception& ex) { | ||
std::cerr << ex.what() << std::endl; | ||
return -1; | ||
} | ||
} | ||
return 0; | ||
} |
This file was deleted.
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright (C) 2012-2015 Leap Motion, Inc. All rights reserved. | ||
#include "stdafx.h" | ||
#include "Benchmark.h" | ||
|
||
static const size_t sc_ncbOuterLoop = | ||
#ifdef _DEBUG | ||
100; | ||
#else | ||
1000; | ||
#endif | ||
|
||
BenchmarkEntry::BenchmarkEntry(const char* name, void(*pfnBM)(Stopwatch&)) : | ||
name(name) | ||
{ | ||
// Benchmark the whole function call | ||
Stopwatch sw; | ||
for (size_t i = sc_ncbOuterLoop; i--;) | ||
pfnBM(sw); | ||
|
||
// Difference over scale | ||
duration = sw; | ||
duration /= sc_ncbOuterLoop; | ||
} |
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,53 @@ | ||
// Copyright (C) 2012-2015 Leap Motion, Inc. All rights reserved. | ||
#pragma once | ||
#include <chrono> | ||
#include <initializer_list> | ||
#include <vector> | ||
|
||
struct Stopwatch { | ||
void Start(void) { | ||
start = std::chrono::profiling_clock::now(); | ||
} | ||
|
||
void Stop(size_t n) { | ||
auto stop = std::chrono::profiling_clock::now(); | ||
std::chrono::duration<double> delta = stop - start; | ||
duration += delta / n; | ||
} | ||
|
||
private: | ||
std::chrono::profiling_clock::time_point start; | ||
std::chrono::duration<double> duration{0}; | ||
|
||
public: | ||
operator std::chrono::duration<double>(void) const { return duration; } | ||
}; | ||
|
||
struct BenchmarkEntry { | ||
/// <summary> | ||
/// Constructs a BenchmarkEntry based on the specified benchmark routine | ||
/// </summary> | ||
/// <param name="name">The name of this entry</param> | ||
/// <param name="pfnBM">The benchmark routine proper</param> | ||
BenchmarkEntry(const char* name, void(*pfnBM)(Stopwatch&)); | ||
|
||
/// <summary> | ||
/// Standard initialization constructor | ||
/// </summary> | ||
BenchmarkEntry(const char* name, std::chrono::duration<double> duration): | ||
name(name), | ||
duration(duration) | ||
{} | ||
|
||
const char* name; | ||
std::chrono::duration<double> duration; | ||
}; | ||
|
||
struct Benchmark { | ||
Benchmark(std::initializer_list<BenchmarkEntry> entries) : | ||
entries(entries.begin(), entries.end()) | ||
{} | ||
|
||
// Successive entries: | ||
std::vector<BenchmarkEntry> entries; | ||
}; |
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 |
---|---|---|
@@ -1,16 +1,19 @@ | ||
if(NOT AUTOWIRING_BUILD_BENCHMARKS) | ||
return() | ||
endif() | ||
|
||
set(AutowiringBenchmarkTest_SRCS | ||
AutowiringBenchmarkTest.cpp | ||
CanBoostPriorityTest.cpp | ||
set(AutoBench_SRCS | ||
AutoBench.cpp | ||
Benchmark.h | ||
Benchmark.cpp | ||
ContextSearchBm.h | ||
ContextSearchBm.cpp | ||
DispatchQueueBm.h | ||
DispatchQueueBm.cpp | ||
Foo.h | ||
PriorityBoost.h | ||
PriorityBoost.cpp | ||
PrintableDuration.h | ||
) | ||
|
||
add_pch(AutowiringBenchmarkTest_SRCS "stdafx.h" "stdafx.cpp") | ||
add_executable(AutowiringBenchmarkTest ${AutowiringBenchmarkTest_SRCS}) | ||
target_link_libraries(AutowiringBenchmarkTest Autowiring AutowiringFixture AutoTesting) | ||
set_property(TARGET AutowiringBenchmarkTest PROPERTY FOLDER "Autowiring") | ||
add_pch(AutoBench_SRCS "stdafx.h" "stdafx.cpp") | ||
add_executable(AutoBench ${AutoBench_SRCS}) | ||
target_link_libraries(AutoBench Autowiring AutowiringFixture AutoTesting) | ||
set_property(TARGET AutoBench PROPERTY FOLDER "Autowiring") | ||
|
||
# This is a unit test, let CMake know this | ||
add_test(NAME AutowiringBenchmarkTest COMMAND $<TARGET_FILE:AutowiringBenchmarkTest>) |
Oops, something went wrong.