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.6.tar.gz (10.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.6-py3-none-any.whl (19.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pgbenchmark-0.0.6.tar.gz
  • Upload date:
  • Size: 10.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.6.tar.gz
Algorithm Hash digest
SHA256 dc2287b2e4347dc4ac4fc2c818360285e717132c2d5846a0f0e8f327cda18f28
MD5 a0b733ddc6adc7569335d0d14dc598ba
BLAKE2b-256 ba823d2e2fc241f76c0c63034bb75387edf9f5ffb159ca05ad6e2323bdaeffc4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pgbenchmark-0.0.6-py3-none-any.whl
  • Upload date:
  • Size: 19.1 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.6-py3-none-any.whl
Algorithm Hash digest
SHA256 e2c3e071714b6afe722b0f8ad26d00cbeae54fa08533093614c0caafb7121900
MD5 c6e5f67b072a44de74f4756c4211fd39
BLAKE2b-256 b47c47d50f09e18357c3ecc44993d415c3e0593155316220a22c2f122eb8b15c

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