Skip to content

xorz57/Stopwatch

Repository files navigation

Stopwatch

Build

Example

#include "Stopwatch/Stopwatch.hpp"

#include <cstdio>
#include <thread>

void f(int duration) {
    std::printf("%s\n", __func__);
    std::this_thread::sleep_for(std::chrono::seconds(duration));
}

int main() {
    stopwatch_t stopwatch;

    stopwatch.start();
    f(1);
    stopwatch.stop();

    std::printf("stopwatch.total() = %lf ms\n", stopwatch.total()); // Not measured

    stopwatch.start();
    f(2);
    stopwatch.stop();

    std::printf("stopwatch.total() = %lf ms\n", stopwatch.total()); // Not measured

    stopwatch.start();
    f(3);
    stopwatch.stop();

    std::printf("stopwatch.total() = %lf ms\n", stopwatch.total()); // Not measured

    stopwatch.restart();
    f(1);
    stopwatch.stop();

    std::printf("stopwatch.total() = %lf ms\n", stopwatch.total()); // Not measured
}

Output

f
stopwatch.total() = 1000.089782 ms
f
stopwatch.total() = 3000.150913 ms
f
stopwatch.total() = 6000.231520 ms
f
stopwatch.total() = 1000.075934 ms

How to Build

Linux & macOS

git clone https://github.com/microsoft/vcpkg.git ~/vcpkg
~/vcpkg/bootstrap-vcpkg.sh

git clone https://github.com/xorz57/Stopwatch.git
cd Stopwatch
cmake -B build -DCMAKE_BUILD_TYPE=Release -S . -DCMAKE_TOOLCHAIN_FILE=~/vcpkg/scripts/buildsystems/vcpkg.cmake
cmake --build build --config Release
ctest --build-config Release

Windows

git clone https://github.com/microsoft/vcpkg.git C:/vcpkg
C:/vcpkg/bootstrap-vcpkg.bat
C:/vcpkg/vcpkg.exe integrate install

git clone https://github.com/xorz57/Stopwatch.git
cd Stopwatch
cmake -B build -DCMAKE_BUILD_TYPE=Release -S . -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake
cmake --build build --config Release
ctest --build-config Release