Commit 99097a94 authored by Noah Orensa's avatar Noah Orensa
Browse files

implement performance margin as a fraction of baseline time

parent 9b5b283d
......@@ -14,6 +14,8 @@ protected:
uint64_t _performanceMargin = 1e6; // 1 ms
double _performanceMarginRatio = 0;
void _checkPerformance();
void _driverRun() override;
......@@ -106,6 +108,11 @@ public:
return performanceMarginNanos(seconds * 1000000000lu);
}
inline PerformanceTest & performanceMarginAsBaselineRatio(double fractionOfBaselineTime) {
_performanceMarginRatio = fractionOfBaselineTime;
return *this;
}
inline PerformanceTest & expect(Status status) {
UnitTest::expect(status);
return *this;
......
......@@ -5,9 +5,23 @@
using namespace dtest;
void PerformanceTest::_checkPerformance() {
if (_bodyTime + _performanceMargin >= _baselineTime) {
_status = Status::TOO_SLOW;
err("Failed to meet performance requirements with margin of " + formatDuration(_performanceMargin));
if (_performanceMarginRatio == 0) {
if (_bodyTime + _performanceMargin >= _baselineTime) {
_status = Status::TOO_SLOW;
err(
"Failed to meet performance requirements with a margin of "
+ formatDuration(_performanceMargin)
);
}
}
else {
if (_bodyTime > _baselineTime * _performanceMarginRatio) {
_status = Status::TOO_SLOW;
err(
"Failed to meet performance requirements of "
+ std::to_string(_performanceMarginRatio) + " of the baseline time"
);
}
}
}
......@@ -31,10 +45,12 @@ void PerformanceTest::_driverRun() {
_checkPerformance();
m << _status
<< _errors
<< _baselineTime;
},
[this] (Message &m) {
m >> _status
>> _errors
>> _baselineTime;
},
[this] (const std::string &error) {
......
......@@ -21,3 +21,32 @@ perf("performance-test", "too-slow")
.baseline([] {
for (int i = 0; i < 1000000; ++i);
});
perf("performance-test", "pass-ratio")
.performanceMarginAsBaselineRatio(0.7)
.body([] {
for (int i = 0; i < 4000000; ++i);
})
.baseline([] {
for (int i = 0; i < 8000000; ++i);
});
perf("performance-test", "too-slow-ratio")
.performanceMarginAsBaselineRatio(0.7)
.expect(Status::TOO_SLOW)
.body([] {
for (int i = 0; i < 8000000; ++i);
})
.baseline([] {
for (int i = 0; i < 8000000; ++i);
});
perf("performance-test", "error-msg")
.expect(Status::TOO_SLOW)
.body([] {
for (int i = 0; i < 8000000; ++i);
err("error from body");
})
.baseline([] {
err("error from baseline");
});
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment