C/C++ API Reference
Loading...
Searching...
No Matches
pw_perf_test

Oveview

Micro-benchmarks that are easy to write and run. Main docs: https://pigweed.dev/pw_perf_test.

Namespaces

namespace  pw
 The Pigweed namespace.
 
namespace  pw::perf_test
 Micro-benchmarks library.
 

Macros

#define PW_PERF_TEST(name, function, ...)
 
#define PW_PERF_TEST_SIMPLE(name, function, ...)
 

Functions

void pw::perf_test::RunAllTests (EventHandler &handler)
 

Macro Definition Documentation

◆ PW_PERF_TEST

#define PW_PERF_TEST (   name,
  function,
  ... 
)
Value:
const ::pw::perf_test::internal::TestInfo PwPerfTest_##name( \
#name, [](::pw::perf_test::State& pw_perf_test_state) { \
static_cast<void>( \
function(pw_perf_test_state PW_COMMA_ARGS(__VA_ARGS__))); \
})

Defines a performance test.

The Framework will create a State and pass it to the provided function. This function should perform whatever behavior is to be measured in a loop as long as State::KeepRunning() returns true.

Example:

void TestFunction(::pw::perf_test::State& state, args...) {
// Create any needed variables.
while (state.KeepRunning()){
// Run code to be measured here.
}
}
PW_PERF_TEST(PerformanceTestName, TestFunction, args...);
#define PW_PERF_TEST(name, function,...)
Definition: perf_test.h:39

◆ PW_PERF_TEST_SIMPLE

#define PW_PERF_TEST_SIMPLE (   name,
  function,
  ... 
)
Value:
name, \
[](::pw::perf_test::State& pw_perf_test_simple_state, \
const auto&... args) { \
while (pw_perf_test_simple_state.KeepRunning()) { \
function(args...); \
} \
}, \
__VA_ARGS__)

Defines a simple performance test.

This macro is similar to PW_PERF_TEST, except that the provided function does not take a State parameter. As a result, the function should NOT call State::KeepRunning(). Instead, the macro calls the function within its own internal state loop.

Example:

void TestFunction(args...) {
// Run code to be measured here.
}
PW_PERF_SIMPLE_TEST(PerformanceTestName, TestFunction, args...);

Function Documentation

◆ RunAllTests()

void pw::perf_test::RunAllTests ( EventHandler handler)

Runs all registered tests,

This function should be called by main. The tests will use the provided handler to report results.