Skip to content

Series of convenience wrappers around std::chrono to assist with timing.

License

Notifications You must be signed in to change notification settings

TimSevereijns/Stopwatch

Repository files navigation

Stopwatch

codecov

Stopwatch is a header-only class that encapsulates the boilerplate needed to time a block of code using the standard std::chrono infrastructure.

Example

Without further ado, here's a basic example of how the class might be used.

const auto stopwatch = Stopwatch<std::chrono::milliseconds>([&] { FunctionToBeTimed(); });

std::cout << "Task completed in " << stopwatch.GetElapsedTime().count() << " "
          << stopwatch.GetUnitsAsString() << ".\n";

The snippet above will result in the following output being printed to the console, assuming that FunctionToBeTimed() completed in exactly one second:

Task completed in 1000 milliseconds.

The following std::chrono types are support as units of measurement:

  • std::chrono::nanoseconds
  • std::chrono::microseconds
  • std::chrono::milliseconds
  • std::chrono::seconds
  • std::chrono::minutes
  • std::chrono::hours

That's it, folks.

About

Series of convenience wrappers around std::chrono to assist with timing.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published