Code Monkey home page Code Monkey logo

stopwatch's Introduction

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 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

stopwatch's People

Contributors

xorz57 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.