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.5.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.5-py3-none-any.whl (19.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pgbenchmark-0.0.5.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.5.tar.gz
Algorithm Hash digest
SHA256 2f046ba204bfec0a8e46f26c56611ce051756e02fe7dd199568691575d303ea7
MD5 7173f05c57f3a40e082fe23212c6b145
BLAKE2b-256 913143d80539fa2ac3ba200f0304ccd891bbe2d05701e4b2872e15274b3fcf08

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pgbenchmark-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 19.2 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.5-py3-none-any.whl
Algorithm Hash digest
SHA256 a75690340793a7afeaa53a831901d1793b73e9ec9df86b71aaee4ba7708e5dee
MD5 28f19f30432e422917ce04b0d8d8e349
BLAKE2b-256 548db9d6d970895459a6961d8ad0cfef322e2ab430516b61a2d801c65c15bdca

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