mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-10-01 14:58:14 +00:00
Four tests had their own copy of "call this until N seconds have passed, then divide". CallsPerSecond in UnitTest.h does it; each keeps its old duration and batch size. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
51 lines
2.4 KiB
C++
51 lines
2.4 KiB
C++
#pragma once
|
|
|
|
#include <cmath>
|
|
#include <cstdio>
|
|
#include <cstring>
|
|
#include <algorithm>
|
|
|
|
#include "Common/TimeUtil.h"
|
|
|
|
// For benchmarks: calls fn over and over, callsPerBatch at a time between reads of the clock, for at
|
|
// least the given number of seconds, and returns how many calls per second that came to. Multiply by
|
|
// the work one call does (pixels, vertices) for a throughput.
|
|
template <typename Func>
|
|
double CallsPerSecond(Func fn, double seconds, int callsPerBatch) {
|
|
int calls = 0;
|
|
const double start = time_now_d();
|
|
do {
|
|
for (int i = 0; i < callsPerBatch; i++) {
|
|
fn();
|
|
}
|
|
calls += callsPerBatch;
|
|
} while (time_now_d() - start < seconds);
|
|
return calls / (time_now_d() - start);
|
|
}
|
|
|
|
inline bool rel_equal(float a, float b, float precision) {
|
|
float diff = fabsf(a - b);
|
|
if (diff == 0.0f) {
|
|
return true;
|
|
}
|
|
float range = std::max(fabsf(a), fabsf(b));
|
|
float quot = diff / range;
|
|
return quot < precision;
|
|
}
|
|
|
|
|
|
#define EXPECT_TRUE(a) if (!(a)) { printf("%s:%i: Test Fail\n", __FUNCTION__, __LINE__); return false; }
|
|
#define EXPECT_FALSE(a) if ((a)) { printf("%s:%i: Test Fail\n", __FUNCTION__, __LINE__); return false; }
|
|
#define EXPECT_EQ_INT(a, b) if ((a) != (b)) { printf("%s:%i: Test Fail\n%d\nvs\n%d\n", __FUNCTION__, __LINE__, (int)(a), (int)(b)); return false; }
|
|
#define EXPECT_EQ_CHAR(a, b) if ((a) != (b)) { printf("%s:%i: Test Fail\n%c\nvs\n%c\n", __FUNCTION__, __LINE__, (int)(a), (int)(b)); return false; }
|
|
#define EXPECT_EQ_HEX(a, b) if ((a) != (b)) { printf("%s:%i: Test Fail\n%x\nvs\n%x\n", __FUNCTION__, __LINE__, a, b); return false; }
|
|
#define EXPECT_EQ_FLOAT(a, b) if ((a) != (b)) { printf("%s:%i: Test Fail\n%0.7f\nvs\n%0.7f\n", __FUNCTION__, __LINE__, a, b); return false; }
|
|
#define EXPECT_APPROX_EQ_FLOAT(a, b) if (fabsf((a)-(b))>0.00001f) { printf("%s:%i: Test Fail\n%f\nvs\n%f\n", __FUNCTION__, __LINE__, a, b); /*return false;*/ }
|
|
#define EXPECT_REL_EQ_FLOAT(a, b, precision) if (!rel_equal(a, b, precision)) { printf("%s:%i: Test Fail\n%0.9f\nvs\n%0.9f\n", __FUNCTION__, __LINE__, a, b); /*return false;*/ }
|
|
#define EXPECT_EQ_STR(a, b) if (a != b) { printf("%s: Test Fail\n%s\nvs\n%s\n", __FUNCTION__, a.c_str(), b.c_str()); return false; }
|
|
#define EXPECT_EQ_MEM(a, b, sz) if (memcmp(a, b, sz) != 0) { printf("%s: Test Fail\n%.*s\nvs\n%.*s\n", __FUNCTION__, (int)sz, a, (int)sz, b); return false; }
|
|
|
|
#define RET(a) if (!(a)) { return false; }
|
|
|
|
extern bool g_testLog;
|