https://github.com/treeform/benchy
Benchmarking.
https://github.com/treeform/benchy
Last synced: 7 months ago
JSON representation
Benchmarking.
- Host: GitHub
- URL: https://github.com/treeform/benchy
- Owner: treeform
- License: mit
- Created: 2020-12-04T04:12:15.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2024-03-07T01:11:05.000Z (over 1 year ago)
- Last Synced: 2025-02-09T01:38:58.194Z (9 months ago)
- Language: Nim
- Size: 99.6 KB
- Stars: 55
- Watchers: 5
- Forks: 8
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-nim - benchy - Simple benchmarking to time your code. (Development Tools / Benchmarking)
README
# Benchy
* `atlas use benchy`
* `nimble install benchy`

[API reference](https://treeform.github.io/benchy)
This library has no dependencies other than the Nim standard library.
## About
Simple benchmarking to time your code. Just put your code in a `timeIt` block. Don't forgot to run with `-d:release`.
```nim
import benchy, std/os, std/random
timeIt "sleep 1ms":
sleep(1)
timeIt "sleep 200ms":
sleep(200)
timeIt "sleep random":
sleep(rand(0 .. 150))
timeIt "number counter":
var s = 0
for i in 0 .. 1_000_000:
s += s
timeIt "string append":
var s = "?"
for i in 0 .. 26:
s.add(s)
```
It will run the `timeIt` block at least 10 times but possibly more to figure out the standard deviation. It will keep running it until things look like they stabilized. It will stop after 60s though.
```
name ............................... min time avg time std dv runs
sleep 1ms .......................... 1.016 ms 1.993 ms ±0.032 x1000
sleep 200ms ...................... 200.403 ms 200.463 ms ±0.022 x25
sleep random ....................... 5.959 ms 75.490 ms ±44.856 x67
number counter ..................... 2.680 ms 2.747 ms ±0.052 x1000
string append ..................... 36.322 ms 37.796 ms ±1.771 x127
```