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

Uploaded Source

File details

Details for the file timerpp-0.4.tar.gz.

File metadata

  • Download URL: timerpp-0.4.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.5

File hashes

Hashes for timerpp-0.4.tar.gz
Algorithm Hash digest
SHA256 43867f5339acf384dfd39ca41df33b32bd4ef6dda75207b75a7539e2ef0a3b34
MD5 2fd5075126b60897c4f93f936b7c865f
BLAKE2b-256 b6863566fbfcbc19dca7f4ab98bdeab0a7cf8dcd92381f086ebfb43083c117e1

See more details on using hashes here.

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