UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
Benchmark.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "CoreGlobals.h"
6#include "CoreTypes.h"
7#include "HAL/PlatformTime.h"
9
10template<uint32 NumRuns, typename TestT>
11void Benchmark(const TCHAR* TestName, TestT&& TestBody)
12{
13 UE_LOG(LogTemp, Log, TEXT("\n-------------------------------\n%s"), TestName);
14 double MinTime = TNumericLimits<double>::Max();
15 double TotalTime = 0;
16 for (uint32 RunNo = 0; RunNo != NumRuns; ++RunNo)
17 {
19 TestBody();
21
22 UE_LOG(LogTemp, Log, TEXT("#%d: %f secs"), RunNo, Time);
23
24 TotalTime += Time;
25 if (MinTime > Time)
26 {
27 MinTime = Time;
28 }
29 }
30 UE_LOG(LogTemp, Log, TEXT("min: %f secs, avg: %f secs\n-------------------------------\n"), MinTime, TotalTime / NumRuns);
31
32#if NO_LOGGING
33 printf("%s\nmin: %f secs, avg: %f secs\n-------------------------------\n\n", TCHAR_TO_ANSI(TestName), MinTime, TotalTime / NumRuns);
34#endif
35}
36
37#define UE_BENCHMARK(NumRuns, ...) { TRACE_CPUPROFILER_EVENT_SCOPE_STR(TEXT(#__VA_ARGS__)); Benchmark<NumRuns>(TEXT(#__VA_ARGS__), __VA_ARGS__); }
38
void Benchmark(const TCHAR *TestName, TestT &&TestBody)
Definition Benchmark.h:11
#define TEXT(x)
Definition Platform.h:1272
FPlatformTypes::TCHAR TCHAR
Either ANSICHAR or WIDECHAR, depending on whether the platform supports wide characters or the requir...
Definition Platform.h:1135
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
#define UE_LOG(CategoryName, Verbosity, Format,...)
Definition LogMacros.h:270
#define TCHAR_TO_ANSI(str)
Definition StringConv.h:1019
uint32_t uint32
Definition binka_ue_file_header.h:6
static double Seconds()
Definition AndroidPlatformTime.h:20
Definition NumericLimits.h:41