From e7d78b095e0ffe53f20ea46b14e533345c74896f Mon Sep 17 00:00:00 2001 From: Ben Kyd Date: Tue, 28 Feb 2023 14:28:41 +0000 Subject: [PATCH] benchmark code --- .gitignore | 3 +++ benchmark/CMakeLists.txt | 7 +++++++ benchmark/benchmark.cpp | 24 ++++++++++++++++++++++++ 3 files changed, 34 insertions(+) create mode 100644 benchmark/CMakeLists.txt create mode 100644 benchmark/benchmark.cpp diff --git a/.gitignore b/.gitignore index 5f9e326..a0bf096 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,8 @@ example/* !example/example.cpp !example/CMakeLists.txt +benchmark/* +!benchmark/benchmark.cpp +!benchmark/CMakeLists.txt .ccls-cache/ compile_commands.json diff --git a/benchmark/CMakeLists.txt b/benchmark/CMakeLists.txt new file mode 100644 index 0000000..f58347a --- /dev/null +++ b/benchmark/CMakeLists.txt @@ -0,0 +1,7 @@ +cmake_minimum_required(VERSION 3.9) + +project(yolo_benchmark) + +add_executable(yolo_benchmark benchmark.cpp) +target_include_directories(yolo_benchmark PRIVATE "../include") + diff --git a/benchmark/benchmark.cpp b/benchmark/benchmark.cpp new file mode 100644 index 0000000..6309f97 --- /dev/null +++ b/benchmark/benchmark.cpp @@ -0,0 +1,24 @@ +#include +#include + +#include "yolo/yolo.hpp" + +int main() +{ + const int iterations = 1000000; + int x = 42; + int y = 123; + + auto start = std::chrono::high_resolution_clock::now(); + for (int i = 0; i < iterations; ++i) + { + yolo::info("value for x is {} and value for y is {}", x, y); + } + auto end = std::chrono::high_resolution_clock::now(); + + auto elapsed = std::chrono::duration_cast(end - start).count(); + + std::cout << "Total time taken: " << elapsed << " ns\n"; + std::cout << "Average time per call: " << static_cast(elapsed) / iterations << " ns\n"; + return 0; +}