diff --git a/base/benchmark.hpp b/base/benchmark.hpp index c34d1599..1d760f06 100644 --- a/base/benchmark.hpp +++ b/base/benchmark.hpp @@ -19,19 +19,21 @@ namespace vks class Benchmark { private: FILE *stream; + VkPhysicalDeviceProperties deviceProps; public: bool active = false; bool outputFrameTimes = false; uint32_t warmup = 1; uint32_t duration = 10; std::vector frameTimes; - std::string filename = "benchmarkresults.csv"; + std::string filename = ""; double runtime = 0.0; uint32_t frameCount = 0; - void run(std::function renderFunc) { + void run(std::function renderFunc, VkPhysicalDeviceProperties deviceProps) { active = true; + this->deviceProps = deviceProps; #if defined(_WIN32) AttachConsole(ATTACH_PARENT_PROCESS); freopen_s(&stream, "CONOUT$", "w+", stdout); @@ -61,19 +63,20 @@ namespace vks frameCount++; }; 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 << "frames: " << frameCount << std::endl; - std::cout << "fps: " << frameCount / (runtime / 1000.0) << std::endl; + std::cout << "frames : " << frameCount << 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); if (result.is_open()) { result << std::fixed << std::setprecision(4); - result << "duration (ms),frames,fps" << std::endl; - result << runtime << "," << frameCount << "," << frameCount / (runtime / 1000.0) << std::endl; + result << "device,driverversion,duration (ms),frames,fps" << std::endl; + result << deviceProps.deviceName << "," << deviceProps.driverVersion << "," << runtime << "," << frameCount << "," << frameCount / (runtime / 1000.0) << std::endl; if (outputFrameTimes) { result << std::endl << "frame,ms" << std::endl; @@ -83,9 +86,9 @@ namespace vks double tMin = *std::min_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(); - std::cout << "best : " << (1000.0 / tMin) << " fps (" << tMin << " 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 << "best : " << (1000.0 / tMin) << " fps (" << tMin << " 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 << std::endl; } diff --git a/base/vulkanexamplebase.cpp b/base/vulkanexamplebase.cpp index fe1b6678..c3ff224c 100644 --- a/base/vulkanexamplebase.cpp +++ b/base/vulkanexamplebase.cpp @@ -275,9 +275,11 @@ void VulkanExampleBase::renderFrame() void VulkanExampleBase::renderLoop() { if (benchmark.active) { - benchmark.run([=] { render(); }); + benchmark.run([=] { render(); }, vulkanDevice->properties); vkDeviceWaitIdle(device); - benchmark.saveResults(title, deviceProperties.deviceName); + if (benchmark.filename != "") { + benchmark.saveResults(); + } return; }