Skip to main content

A Python package to benchmark query performance and comparison on PostgreSQL Database

Project description

pgbenchmark

pgbenchmark is a Python package to benchmark query performance on a PostgreSQL database. It allows you to measure the execution time of queries over multiple runs, providing detailed metrics about each run's performance.

⚠️ This library is under HEAVY development ⚠️
I'll try to keep everything backwards compatible...

Getting Started

pip install pgbenchmark

Extremely simple setup.

import psycopg2
from pgbenchmark import Benchmark

conn = psycopg2.connect(
    "<< YOUR CONNECTION >>"
)

benchmark = Benchmark(db_connection=conn, number_of_runs=1000)
benchmark.set_sql("./test.sql")

for result in benchmark:
    # {'run': X, 'sent_at': <DATETIME WITH MS>, 'duration': '0.000064'}
    pass

""" View Summary """
print(benchmark.get_execution_results())
# {'runs': 1000, 'min_time': '0.00005', 'max_time': '0.000287', 'avg_time': '0.000072'}

You can also pass raw SQL as a String, instead of file

benchmark.set_sql("SELECT 1;")

It also supports SQLAlchemy connection engine

engine = create_engine("postgresql+psycopg2://.......")
conn = engine.connect()

# Set up benchmark class
benchmark = Benchmark(db_connection=conn, number_of_runs=5)

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

pgbenchmark-0.0.4.tar.gz (7.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pgbenchmark-0.0.4-py3-none-any.whl (15.3 kB view details)

Uploaded Python 3

File details

Details for the file pgbenchmark-0.0.4.tar.gz.

File metadata

  • Download URL: pgbenchmark-0.0.4.tar.gz
  • Upload date:
  • Size: 7.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for pgbenchmark-0.0.4.tar.gz
Algorithm Hash digest
SHA256 b5c33a21a93a4bc68b2ffc84c89bb02a03f63e03869b3b9b8def448e07fcce23
MD5 fc969240f3c5abe1f8cbf9d41d3d3c66
BLAKE2b-256 b914a7c191b1691f15ec09171e78605a5c06e18349e05375c900370875183253

See more details on using hashes here.

File details

Details for the file pgbenchmark-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: pgbenchmark-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 15.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for pgbenchmark-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 5816325322086af7292392560ed9e9520103bdf5fe2d2c606822a25bc5d4ddc9
MD5 fa9e3f1008be929fe6cd9a88d9c68c07
BLAKE2b-256 bec31e26c6f25b4239f9bd252672c6f8eaebbc444a4b1477f60f102068ecb93e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page