https://github.com/briandowns/libbenchmark
loads is a simple library to benchmark C functions across a given number of threads.
https://github.com/briandowns/libbenchmark
benchmark c performance threads
Last synced: 5 months ago
JSON representation
loads is a simple library to benchmark C functions across a given number of threads.
- Host: GitHub
- URL: https://github.com/briandowns/libbenchmark
- Owner: briandowns
- License: bsd-2-clause
- Created: 2019-08-12T02:45:38.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2024-11-04T15:52:33.000Z (over 1 year ago)
- Last Synced: 2025-04-11T02:08:20.072Z (about 1 year ago)
- Topics: benchmark, c, performance, threads
- Language: C
- Homepage:
- Size: 29.3 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# libbenchmark
[](https://travis-ci.org/briandowns/libbenchmark/)
[](https://opensource.org/licenses/BSD-2-Clause)

libbenchmark is a small library that provides a single function named `benchmark` to perform micro-benchmarks on a given function spread across a given number of threads. This library was heavily inspired by [Tidwall's](github.com/tidwall) [lotsa](github.com/tidwall/lotsa) Go package.
Operation:
`benchmark` takes 3 arguments. The first is the number of times you want the function executed, the second is the number of threads, and the third, the function you want executed. If either the number of operations or threads is less than 1 `-1` is returned indicating an error state. If the thread count is 1, execution will remain in the current process however if it's larger than 1, execution will be distributed across the threads evenly based on the number of operations given.
## Example
```c
#include
#include
#include "benchmark.h"
void
fizz_buzz(uint64_t i)
{
if (i % 15 == 0) {
printf("fizzbuzz\n");
} else if (i % 5 == 0) {
printf("buzz\n");
} else if (i % 3 == 0) {
printf("fizz\n");
} else {
printf("%llu\n", i);
}
}
int
main(int argc, char** argv)
{
benchmark(100, 10, fizz_buzz);
return 0;
}
```
Output:
```sh
100 ops over 10 threads in 0.001524 sec, inf/sec 15240.00 ns/op
```
## Test
```sh
make test
```
## Installation
Installation is currently supported on Linux and MacOS. There will be an effort to get this installed on FreeBSD soon.
```sh
make install
```
## Contributing
Please feel free to open a PR!
## License
libbenchmark source code is available under the BSD 2 clause [License](/LICENSE).
## Contact
[@bdowns328](http://twitter.com/bdowns328)