-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First draft of (experimental) benchmarking support
- Loading branch information
1 parent
a1e3f0b
commit a9b6813
Showing
14 changed files
with
227 additions
and
20 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Created by Phil on 04/07/2017. | ||
* Copyright 2017 Two Blue Cubes Ltd. All rights reserved. | ||
* | ||
* Distributed under the Boost Software License, Version 1.0. (See accompanying | ||
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | ||
*/ | ||
|
||
#include "catch_benchmark.h" | ||
#include "catch_capture.hpp" | ||
|
||
namespace Catch { | ||
|
||
void BenchmarkLooper::reportStart() const { | ||
getResultCapture().benchmarkStarting( { m_name } ); | ||
} | ||
auto BenchmarkLooper::needsMoreIterations() -> bool { | ||
auto elapsed = m_timer.getElapsedNanoseconds(); | ||
|
||
// Exponentially increasing iterations until we're confident in our timer resolution | ||
if( elapsed < m_resolution ) { | ||
m_iterationsToRun *= 10; | ||
return true; | ||
} | ||
|
||
getResultCapture().benchmarkEnded( { { m_name }, m_count, elapsed } ); | ||
return false; | ||
} | ||
|
||
} // end namespace Catch |
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,55 @@ | ||
/* | ||
* Created by Phil on 04/07/2017. | ||
* Copyright 2017 Two Blue Cubes Ltd. All rights reserved. | ||
* | ||
* Distributed under the Boost Software License, Version 1.0. (See accompanying | ||
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | ||
*/ | ||
#ifndef TWOBLUECUBES_CATCH_BENCHMARK_H_INCLUDED | ||
#define TWOBLUECUBES_CATCH_BENCHMARK_H_INCLUDED | ||
|
||
#include "catch_stringref.h" | ||
#include "catch_timer.h" | ||
|
||
#include <cstdint> | ||
#include <string> | ||
|
||
namespace Catch { | ||
|
||
class BenchmarkLooper { | ||
|
||
std::string m_name; | ||
size_t m_count = 0; | ||
size_t m_iterationsToRun = 1; | ||
uint64_t m_resolution; | ||
Timer m_timer; | ||
public: | ||
// Keep most of this inline as it's on the code path that is being timed | ||
BenchmarkLooper( StringRef name ) | ||
: m_name( name.c_str() ), | ||
m_resolution( getEstimatedClockResolution()*10 ) | ||
{ | ||
reportStart(); | ||
m_timer.start(); | ||
} | ||
|
||
explicit operator bool() { | ||
if( m_count < m_iterationsToRun ) | ||
return true; | ||
return needsMoreIterations(); | ||
} | ||
|
||
void increment() { | ||
++m_count; | ||
} | ||
|
||
void reportStart() const; | ||
auto needsMoreIterations() -> bool; | ||
}; | ||
|
||
} // end namespace Catch | ||
|
||
#define BENCHMARK( name ) \ | ||
for( Catch::BenchmarkLooper looper( name ); looper; looper.increment() ) | ||
|
||
#endif // TWOBLUECUBES_CATCH_BENCHMARK_H_INCLUDED |
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
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.