parent
9e073bdd3b
commit
f252284fa5
2 changed files with 17 additions and 12 deletions
|
|
@ -19,19 +19,21 @@ namespace vks
|
||||||
class Benchmark {
|
class Benchmark {
|
||||||
private:
|
private:
|
||||||
FILE *stream;
|
FILE *stream;
|
||||||
|
VkPhysicalDeviceProperties deviceProps;
|
||||||
public:
|
public:
|
||||||
bool active = false;
|
bool active = false;
|
||||||
bool outputFrameTimes = false;
|
bool outputFrameTimes = false;
|
||||||
uint32_t warmup = 1;
|
uint32_t warmup = 1;
|
||||||
uint32_t duration = 10;
|
uint32_t duration = 10;
|
||||||
std::vector<double> frameTimes;
|
std::vector<double> frameTimes;
|
||||||
std::string filename = "benchmarkresults.csv";
|
std::string filename = "";
|
||||||
|
|
||||||
double runtime = 0.0;
|
double runtime = 0.0;
|
||||||
uint32_t frameCount = 0;
|
uint32_t frameCount = 0;
|
||||||
|
|
||||||
void run(std::function<void()> renderFunc) {
|
void run(std::function<void()> renderFunc, VkPhysicalDeviceProperties deviceProps) {
|
||||||
active = true;
|
active = true;
|
||||||
|
this->deviceProps = deviceProps;
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
AttachConsole(ATTACH_PARENT_PROCESS);
|
AttachConsole(ATTACH_PARENT_PROCESS);
|
||||||
freopen_s(&stream, "CONOUT$", "w+", stdout);
|
freopen_s(&stream, "CONOUT$", "w+", stdout);
|
||||||
|
|
@ -61,19 +63,20 @@ namespace vks
|
||||||
frameCount++;
|
frameCount++;
|
||||||
};
|
};
|
||||||
std::cout << "Benchmark finished" << std::endl;
|
std::cout << "Benchmark finished" << std::endl;
|
||||||
|
std::cout << "device : " << deviceProps.deviceName << " (driver version: " << deviceProps.driverVersion << ")" << std::endl;
|
||||||
std::cout << "runtime: " << (runtime / 1000.0) << std::endl;
|
std::cout << "runtime: " << (runtime / 1000.0) << std::endl;
|
||||||
std::cout << "frames: " << frameCount << std::endl;
|
std::cout << "frames : " << frameCount << std::endl;
|
||||||
std::cout << "fps: " << frameCount / (runtime / 1000.0) << std::endl;
|
std::cout << "fps : " << frameCount / (runtime / 1000.0) << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void saveResults(std::string appinfo, std::string deviceinfo) {
|
void saveResults() {
|
||||||
std::ofstream result(filename, std::ios::out);
|
std::ofstream result(filename, std::ios::out);
|
||||||
if (result.is_open()) {
|
if (result.is_open()) {
|
||||||
result << std::fixed << std::setprecision(4);
|
result << std::fixed << std::setprecision(4);
|
||||||
|
|
||||||
result << "duration (ms),frames,fps" << std::endl;
|
result << "device,driverversion,duration (ms),frames,fps" << std::endl;
|
||||||
result << runtime << "," << frameCount << "," << frameCount / (runtime / 1000.0) << std::endl;
|
result << deviceProps.deviceName << "," << deviceProps.driverVersion << "," << runtime << "," << frameCount << "," << frameCount / (runtime / 1000.0) << std::endl;
|
||||||
|
|
||||||
if (outputFrameTimes) {
|
if (outputFrameTimes) {
|
||||||
result << std::endl << "frame,ms" << std::endl;
|
result << std::endl << "frame,ms" << std::endl;
|
||||||
|
|
@ -83,9 +86,9 @@ namespace vks
|
||||||
double tMin = *std::min_element(frameTimes.begin(), frameTimes.end());
|
double tMin = *std::min_element(frameTimes.begin(), frameTimes.end());
|
||||||
double tMax = *std::max_element(frameTimes.begin(), frameTimes.end());
|
double tMax = *std::max_element(frameTimes.begin(), frameTimes.end());
|
||||||
double tAvg = std::accumulate(frameTimes.begin(), frameTimes.end(), 0.0) / (double)frameTimes.size();
|
double tAvg = std::accumulate(frameTimes.begin(), frameTimes.end(), 0.0) / (double)frameTimes.size();
|
||||||
std::cout << "best : " << (1000.0 / tMin) << " fps (" << tMin << " ms)" << std::endl;
|
std::cout << "best : " << (1000.0 / tMin) << " fps (" << tMin << " ms)" << std::endl;
|
||||||
std::cout << "worst: " << (1000.0 / tMax) << " fps (" << tMax << " ms)" << std::endl;
|
std::cout << "worst : " << (1000.0 / tMax) << " fps (" << tMax << " ms)" << std::endl;
|
||||||
std::cout << "avg : " << (1000.0 / tAvg) << " fps (" << tAvg << " ms)" << std::endl;
|
std::cout << "avg : " << (1000.0 / tAvg) << " fps (" << tAvg << " ms)" << std::endl;
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -275,9 +275,11 @@ void VulkanExampleBase::renderFrame()
|
||||||
void VulkanExampleBase::renderLoop()
|
void VulkanExampleBase::renderLoop()
|
||||||
{
|
{
|
||||||
if (benchmark.active) {
|
if (benchmark.active) {
|
||||||
benchmark.run([=] { render(); });
|
benchmark.run([=] { render(); }, vulkanDevice->properties);
|
||||||
vkDeviceWaitIdle(device);
|
vkDeviceWaitIdle(device);
|
||||||
benchmark.saveResults(title, deviceProperties.deviceName);
|
if (benchmark.filename != "") {
|
||||||
|
benchmark.saveResults();
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue