Skip to main content

timesup

🚧 There's no source code available yet. Stay tuned.

Library that handles all boilerplate when it comes to measuring performance and showcasing the difference between results.

Why?

I was tired of writing benchmarks that not only measured performance, but also output it in an accessible and intuitive way (like this one), but also easy to reproduce. So I decided to abstract all that away so the only thing left is to write the actual code you want to measure.

I believe that by making benchmarking more accessible (and fun), I can create incentive to build faster software.

Features

  • Output is a Python code that contains the benchmark itself and ready to be published
  • Effortless comparisons of results
  • Compare current implementation to one in any given git revision
  • Compare interpreted CPython code to compiled code it produces via cython or mypyc
  • Profiling support for expressions
  • HTML output for viewing individual profiling results by expanding expressions
  • Automatically selects the appropriate number of runs and repeats, if they weren't provided
  • Out-of-the-box support for multiline expressions

Showcase

All snippets are self-contained

Comparing within the same process

cat benchmark.py

import copy
import duper
import timesup

@timesup.it(number=100000, repeats=3)
def duper_vs_deepcopy():
    x = {"a": 1, "b": [(1, 2, 3), (4, 5, 6)], "c": []}  # i
    copy.deepcopy(x)  # t deepcopy
    dup = duper.Duper(x)  # t duper_init deepcopy
    dup.deep()  # t duper deepcopy

python benchmark.py

import copy
import duper
import timesup

@timesup.it(number=100000, repeats=3)
def reconstruction():
    x = {"a": 1, "b": [(1, 2, 3), (4, 5, 6)], "c": []} 
    copy.deepcopy(x)        # ~0.00643 ms (deepcopy)
    dup = duper.Duper(x)    # ~0.00009 ms (duper_init): 69.44 times faster than deepcopy
    dup.deep()              # ~0.00014 ms (duper): 44.76 times faster than deepcopy

Interpreted vs compiled code

cat fib.py
def fib(n: int) -> int:
    if n <= 1:
        return n
    else:
        return fib(n - 2) + fib(n - 1)

mypyc fib.py

building 'compiled_test' extension
...
copying build/lib.macosx-12.0-arm64-cpython-310/fib.cpython-310-darwin.so -> 

cat benchmark.py

import timesup
from fib import fib

@timesup.compare(to_interpreted=True)
def cpython_vs_mypyc():
    fib(32)

python benchmark.py

import timesup
from fib import fib

@timesup.compare(to_interpreted=True)
def cpython_vs_mypyc():
    fib(32)     # ~510.73292 ms (interpreted)
    #|_________ # ~21.72464 ms (compiled): 23.51 times faster than interpreted

Existing vs new code

Consider you're trying to improve performance of app.used_to_be_slow function.

It's crucial to have a baseline that you can compare your changes to.

By allowing to pass a target revision that changes need to be compared to, timesup:

  • removes the need to capture the baseline beforehand
  • since baseline is calculated each time automatically, you're not limited to the input you've got your baseline results with
  • creates a perfect code snippet to include in PR with the changes ✨
  • this snipped can be run by any of reviewers without them needing to manually download any benchmarks, measuring the baseline and testing the results

cat benchmark.py

import timesup
from app import used_to_be_slow

@timesup.compare(to_revision="main")
def measure_improvement():
    used_to_be_slow()

python benchmark.py

import timesup
from app import used_to_be_slow

@timesup.compare(to_revision="main")
def measure_improvement():
    used_to_be_slow()     # ~0.00106 ms (34dc8225)
    #|___________________ # ~0.00035 ms (changes): 2.99 times faster than 34dc8225 

🚧 Status

If you have any feedback, you can open the issue, or contact me directly via bobronium@gmail.com or Telegram.

Metadata

Release files for timesup 0.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for timesup 0.0.0
File Size Uploaded Provenance
timesup-0.0.0.tar.gz 1.2 MB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for timesup 0.0.0
File Interpreter ABI Platform
timesup-0.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 1.2 MB

Release files / timesup-0.0.0.tar.gz

Download URL timesup-0.0.0.tar.gz
Size 1.2 MB
Tags Source
SHA-256 checksum
How to use checksums
09b35a81589219a37f5d026099c1bda58233b850173115035a52117673c8a0c0
BLAKE2b-256 checksum
How to use checksums
ff0cec993bbe50e4112a4044344b8471ed6d061f7f3c1bf75cc840ae0b68142e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-httpx/0.23.3

Release files / timesup-0.0.0-py3-none-any.whl

Download URL timesup-0.0.0-py3-none-any.whl
Size 3.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c59896c43583f040eeeb6b39decfdbc18bc41b1f38ded1e3ddf1696c3d9ce15d
BLAKE2b-256 checksum
How to use checksums
d04d4cccafe51e782124ae8fff3778a735a4d7fc37f94cd6fb194d38e6da52d8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-httpx/0.23.3

Security for timesup 0.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page