Just the benchmarking boilerplate, so I don't have to type it all the time
  • HTML 73.1%
  • JavaScript 17.8%
  • CSS 8.5%
  • Python 0.6%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-06-14 20:00:24 +02:00
docs Sphinx docs 2026-06-14 20:00:24 +02:00
src Sphinx docs 2026-06-14 20:00:24 +02:00
.gitignore Initial commit 2025-08-08 11:26:35 +02:00
LICENSE Sphinx docs 2026-06-14 20:00:24 +02:00
MANIFEST.in Sphinx docs 2026-06-14 20:00:24 +02:00
pyproject.toml Sphinx docs 2026-06-14 20:00:24 +02:00
README.rst Sphinx docs 2026-06-14 20:00:24 +02:00

tinybench
=========

*tinybench is my benchmark boilerplate to quick-test stuff.  I also have this
as a snippet, but having it as a package seems more useful.*

Tinybench runs a given list of functions using `timeit` and spits out some
basic statistics on them.

Synopsis
--------

.. code:: bash

   from tinybench import bench

   def f1(): ...  # implementation version 1
   def f2(): ...  # implementation version 2

   bench(f1, f2)

   # or to do 3 runs of 10_000 calls each:
   bench(f1, f2, runs=3, number=10_000)

Usage
-----

There's not much more to add to the example above, except that `timeit.timeit`
expects a function without arguments.  So if you want to benchmark an already
existing function that requires parameters, you have to create a partial of it
or wrap it in a lambda or function that provides these.

The following call shows the defaults.  `number` goes directly into `timeit`,
runs is just a loop over multiple `timeit` calls to have another layer to
average out random load spikes on the computer::

   bench(fn1, fn2, ..., number=1_000_000, runs=5)

This will run 5 iterations of `timeit(f1, number=1_000_000)`, followed by all
other given `fnNN`.  It collects the average, median, and stdev for each
function and run, and will also print out the timing results while the
benchmark is running, so you have a "still alive" sign.

Finally, it will print all run-statistics as well as stats over the runs as
summary.

Installation
------------

This module is not specialized and thorough enough for pypi, it's only on my
github.  Install it with::

   pip install git+https://github.com/dickerdackel/tinybench

Documentation
-------------

The html docs are embedded.  Just use::

   python3 -m tinybench.docs [PORT]

Then point the browser to the reported URL.

Support / Contributing
----------------------

Issues can be opened on `github issues`_

.. _github issues: https://github.com/dickerdackel/tinyecs/issues

Please respect, that I don't want any contributions done with the assistance
of AI.  This is a hobby project with focus on the craft of programming.  I
have experimentally used AI to audit parts of the code and documentation, and
while it found a lot of typos and 2 actual issues, without exception, the
provided solutions were often besides the point or plain wrong.

I have no possibility to enforce that request, the simple fact that I ask for
it should be sufficient.

License
-------

This software is provided under the MIT license.

See LICENSE file for details.