Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/xorz57/stopwatch

Stopwatch written in C++11
https://github.com/xorz57/stopwatch

cpp cpp-library cpp11 cpp11-library header-only header-only-library stopwatch stopwatch-library

Last synced: 3 months ago
JSON representation

Stopwatch written in C++11

Awesome Lists containing this project

README

        

# Stopwatch

[![Build](https://github.com/xorz57/Stopwatch/actions/workflows/Build.yml/badge.svg)](https://github.com/xorz57/Stopwatch/actions/workflows/Build.yml)

## Example

```cpp
#include "Stopwatch/Stopwatch.hpp"

#include
#include

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

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

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

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