Skip to main content

timer class

Project description

timerpp

features

  • header only
  • tested
  • no dependencies
  • python bindings
    • pip3 install git+https://github.com/nbdy/timerpp
    • pip3 install timerpp

example

cpp

#include "timerpp.h"
#include <iostream>

int main() {
  uint64_t lastTimestamp = TIMESTAMP_MS;
  uint64_t newTimestamp = 0;
  uint32_t x = 0;
  timerpp::Timer t([&x, &newTimestamp, &lastTimestamp]{
    newTimestamp = TIMESTAMP_MS;
    x += newTimestamp - lastTimestamp;
    lastTimestamp = newTimestamp;
  });

  t.start(500);
  std::this_thread::sleep_for(Milliseconds(1501));
  t.stop();

  std::cout << "1500 == " <<  x << std::endl;

  return 0;
}

python

from timerpp import Timer
from time import sleep


class Example(Timer):
  elapsed_ms = 0

  def __init__(self):
    Timer.__init__(self, self.callback, 500)

  def callback(self):
    self.elapsed_ms += 500


e = Example()
e.start()
sleep(1.49)
e.stop()
print(f"elapsed_ms: {e.elapsed_ms}")

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

timerpp-0.4.tar.gz (4.0 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page