MicroBenchmark
Public Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
UMicroBenchmarkSubsystem Class Reference

#include <MicroBenchmarkSubsystem.h>

Inherits UGameInstanceSubsystem.

Public Member Functions

void ResetAll ()
 reset all currently logged benchmark timings.
 
void Tic (const FName BenchmarkName="MyBenchmark", const bool bReset=false)
 Start a benchmark. usage. tic -> code to benchmark -> toc. More...
 
int64 Toc (const FName BenchmarkName="MyBenchmark", const bool bShowLog=false)
 stop a benchmark. usage. tic -> code to benchmark -> toc More...
 
void PrintMicroBenchmarkResults (const FName BenchmarkName=NAME_None)
 Print the results of all/any micro benchmarks running this session. More...
 
int64 GetBenchmarkResultAverage (FName BenchmarkName="MyBenchmark")
 Retrieve the average execution time of the specified benchmark. More...
 

Static Protected Member Functions

static FString BeautifyDuration (std::chrono::nanoseconds input_ns)
 convert the supplied nanosecond amount to human-readable string
 

Protected Attributes

TMap< FName, std::chrono::nanoseconds > OpenBenchmarks
 all benchmarks from the since last reset call
 
TMap< FName, FBenchResultBenchmarkResults
 all timed benchmark results since the last reset call
 
std::chrono::nanoseconds Overhead = std::chrono::nanoseconds(0)
 Approximate overhead of calling tic and toc.
 

Detailed Description

Subsystem for Micro Benchmarks

Easy to use micro benchmarking timer tool. Get accurate timings for any code blocks in Blueprints or C++. Simply call "tic" right before the code block you want to time and call "toc" directly after. Either print the results immediately (setting "bShowLog" in "toc" to "true") or periodically print micro benchmark results.

Member Function Documentation

◆ GetBenchmarkResultAverage()

int64 UMicroBenchmarkSubsystem::GetBenchmarkResultAverage ( FName  BenchmarkName = "MyBenchmark")

Retrieve the average execution time of the specified benchmark.

Parameters
BenchmarkNamebenchmark name to retrieve.
Returns
Time in nanoseconds or -1 if not exists.

◆ PrintMicroBenchmarkResults()

void UMicroBenchmarkSubsystem::PrintMicroBenchmarkResults ( const FName  BenchmarkName = NAME_None)

Print the results of all/any micro benchmarks running this session.

Parameters
BenchmarkNamebenchmark name, defaults to None to print all running benchmarks

◆ Tic()

void UMicroBenchmarkSubsystem::Tic ( const FName  BenchmarkName = "MyBenchmark",
const bool  bReset = false 
)

Start a benchmark. usage. tic -> code to benchmark -> toc.

Parameters
BenchmarkNamebenchmark name. if a benchmark with the supplied name is already runnign it will get reset.
bResetreset any averaged benchmark results for this benchmark name

◆ Toc()

int64 UMicroBenchmarkSubsystem::Toc ( const FName  BenchmarkName = "MyBenchmark",
const bool  bShowLog = false 
)

stop a benchmark. usage. tic -> code to benchmark -> toc

Parameters
BenchmarkNamebenchmark name
bShowLogdirectly show output of tic -> toc time. not recommending for short benchmarks (e.g. within your Tick functions)
Returns
nanoseconds of benchmark

The documentation for this class was generated from the following files: