https://github.com/maurodelazeri/elapsed_timer
header-only lib record time elapsed using C++11
https://github.com/maurodelazeri/elapsed_timer
cpp elapsed-time header-only library
Last synced: 3 months ago
JSON representation
header-only lib record time elapsed using C++11
- Host: GitHub
- URL: https://github.com/maurodelazeri/elapsed_timer
- Owner: maurodelazeri
- Created: 2019-08-07T14:55:09.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2019-08-07T15:29:38.000Z (almost 6 years ago)
- Last Synced: 2025-01-05T09:22:08.015Z (4 months ago)
- Topics: cpp, elapsed-time, header-only, library
- Language: C++
- Homepage:
- Size: 6.84 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Elapsed time for code blocks execution written in C++11
This is a simple header-only library `elapsed.h` just import in your project and you are ready to go...
Here an example...
```C++
#include
#include "elapsed.h"
#include "iostream"using namespace std;
void Fibonacci()
{
int t1 = 0, t2 = 1, nextTerm = 0, n;
n = 10;
cout << "Fibonacci Series: " << t1 << ", " << t2 << ", ";
nextTerm = t1 + t2;
while(nextTerm <= n)
{
cout << nextTerm << ", ";
t1 = t2;
t2 = nextTerm;
nextTerm = t1 + t2;
}
}int main() {
{
Elapsed elapsed;
Fibonacci();
}
{
auto elapsed = make_unique("Fibonacci func execution");
Fibonacci();
}
return 0;
}
```Basically when `Elapsed elapsed;` go out of scope it will automatically display the elapsed time in `std::cout`
The execution above will produce something like:
```
Fibonacci Series: 0, 1, 1, 2, 3, 5, 8,
[ Elapsed time: : 15 us ]
Fibonacci Series: 0, 1, 1, 2, 3, 5, 8,
[ Fibonacci func execution : 1 us ]
```