https://github.com/nbdy/timerpp
single header timer library
https://github.com/nbdy/timerpp
header-only python-bindings soft-timer timer
Last synced: about 2 months ago
JSON representation
single header timer library
- Host: GitHub
- URL: https://github.com/nbdy/timerpp
- Owner: nbdy
- License: mit
- Created: 2021-11-14T03:05:48.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2021-12-22T15:42:39.000Z (about 4 years ago)
- Last Synced: 2025-03-19T19:16:42.411Z (9 months ago)
- Topics: header-only, python-bindings, soft-timer, timer
- Language: C++
- Homepage:
- Size: 7.81 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# timerpp
# features
- [X] header only
- [X] [tested](tests.cpp)
- [X] no dependencies
- [X] python bindings
- `pip3 install git+https://github.com/nbdy/timerpp`
- `pip3 install timerpp`
# example
## cpp
```c++
#include "timerpp.h"
#include
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
```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}")
```