Skip to main content

A microbenchmark for Python

Project description

Tinybench Build Status

Tinybench is a lightweight package to time, compare, and visualize various functions. This package was inspired by the R package microbenchmark

Installation

pip install tinybench

Usage

from tinybench import benchmark, benchmark_env

# create two functions example functions to test
def foo(a):
	test = []
	for i in range(a):
		test.append(i)
	return test

def bar(a, b):
	return a + b

# example input variable
c = 10000

iterations = 100
warmup = 10

# env should be globals(), or use benchmark_env(functions_list)
# functions_list should at least contain all the functions to benchmark
env = benchmark_env([foo, bar])

# instead, using globals() is recommended
env = globals()

b = benchmark(['Foo_Label:foo(c)', 'bar(10, 15)'], iterations, warmup, env)
print(b)
b.plot()

# alternatively, we can benchmark using the process time instead of real time:
b_process = benchmark(['Foo_Label:foo(c)', 'bar(10, 15)'], iterations, warmup, env, process_time = True)

Support

For any help or questions, please open an issue on GitHub.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tinybench-1.0.2.tar.gz (4.3 kB view hashes)

Uploaded source

Built Distribution

tinybench-1.0.2-py3-none-any.whl (6.1 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page