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

Uploaded Python 3

File details

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

File metadata

  • Download URL: pgbenchmark-0.0.7.tar.gz
  • Upload date:
  • Size: 10.5 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.7.tar.gz
Algorithm Hash digest
SHA256 c237ea91f497b917938640eb4eb53d764a5a76ace9260ccbbf2331859a3a0a21
MD5 a71090bf2f6e563b483346d39e1a8d7a
BLAKE2b-256 3e2920d5aef9a3dd5f05603c618b4fd37866776d2cb1abdf15a4c778280d4e9d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pgbenchmark-0.0.7-py3-none-any.whl
  • Upload date:
  • Size: 19.6 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.7-py3-none-any.whl
Algorithm Hash digest
SHA256 c3ee7d805d38162ea815cc33de8455dfa949344ca13373a22e8f9abb39283b49
MD5 d85823b4c7365a3fc5e4ff37c0be0fa6
BLAKE2b-256 eb8c1abc60f2a6d7aa75c135326fd456956ad3991a23f5b156d0d6fe3fb5a134

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