|
2 | 2 |
|
3 | 3 | This directory contains benchmark scripts for testing the performance of various database operations using `pyodbc` and `mssql_python`. The goal is to evaluate and compare the performance of these libraries for common database operations. |
4 | 4 |
|
| 5 | +## Benchmark Scripts |
| 6 | + |
| 7 | +### 1. `bench_mssql.py` - Richbench Framework Benchmarks |
| 8 | +Comprehensive benchmarks using the richbench framework for detailed performance analysis. |
| 9 | + |
| 10 | +### 2. `perf-benchmarking.py` - Real-World Query Benchmarks |
| 11 | +Standalone script that tests real-world queries against AdventureWorks2022 database with statistical analysis. |
| 12 | + |
5 | 13 | ## Why Benchmarks? |
6 | 14 | - To measure the efficiency of `pyodbc` and `mssql_python` in handling database operations. |
7 | 15 | - To identify performance bottlenecks and optimize database interactions. |
8 | 16 | - To ensure the reliability and scalability of the libraries under different workloads. |
9 | 17 |
|
10 | 18 | ## How to Run Benchmarks |
| 19 | + |
| 20 | +### Running bench_mssql.py (Richbench Framework) |
| 21 | + |
11 | 22 | 1. **Set Up the Environment Variable**: |
12 | 23 | - Ensure you have a running SQL Server instance. |
13 | 24 | - Set the `DB_CONNECTION_STRING` environment variable with the connection string to your database. For example: |
14 | | - ```cmd |
15 | | - set DB_CONNECTION_STRING=Server=your_server;Database=your_database;UID=your_user;PWD=your_password; |
| 25 | + ```bash |
| 26 | + export DB_CONNECTION_STRING="Server=your_server;Database=AdventureWorks2022;UID=your_user;PWD=your_password;" |
16 | 27 | ``` |
17 | 28 |
|
18 | 29 | 2. **Install Richbench - Benchmarking Tool**: |
19 | | - - Install richbench : |
20 | | - ```cmd |
21 | | - pip install richbench |
22 | | - ``` |
| 30 | + ```bash |
| 31 | + pip install richbench |
| 32 | + ``` |
23 | 33 |
|
24 | 34 | 3. **Run the Benchmarks**: |
25 | | - - Execute richbench from the parent folder (mssql-python) : |
26 | | - ```cmd |
| 35 | + - Execute richbench from the parent folder (mssql-python): |
| 36 | + ```bash |
27 | 37 | richbench benchmarks |
28 | 38 | ``` |
29 | | - Results will be displayed in the terminal with detailed performance metrics. |
| 39 | + - Results will be displayed in the terminal with detailed performance metrics. |
| 40 | + |
| 41 | +### Running perf-benchmarking.py (Real-World Queries) |
| 42 | + |
| 43 | +This script tests performance with real-world queries from the AdventureWorks2022 database. |
| 44 | + |
| 45 | +1. **Prerequisites**: |
| 46 | + - AdventureWorks2022 database must be available |
| 47 | + - Both `pyodbc` and `mssql-python` must be installed |
| 48 | + - Update the connection string in the script if needed |
| 49 | + |
| 50 | +2. **Run from project root**: |
| 51 | + ```bash |
| 52 | + python benchmarks/perf-benchmarking.py |
| 53 | + ``` |
| 54 | + |
| 55 | +3. **Features**: |
| 56 | + - Runs each query multiple times (default: 5 iterations) |
| 57 | + - Calculates average, min, max, and standard deviation |
| 58 | + - Provides speedup comparisons between libraries |
| 59 | + - Tests various query patterns: |
| 60 | + - Complex joins with aggregations |
| 61 | + - Large dataset retrieval (10K+ rows) |
| 62 | + - Very large dataset (1.2M rows) |
| 63 | + - CTEs and subqueries |
| 64 | + - Detailed summary tables and conclusions |
| 65 | + |
| 66 | +4. **Output**: |
| 67 | + The script provides: |
| 68 | + - Progress indicators during execution |
| 69 | + - Detailed results for each benchmark |
| 70 | + - Summary comparison table |
| 71 | + - Overall performance conclusion with speedup factors |
30 | 72 |
|
31 | 73 | ## Key Features of `bench_mssql.py` |
32 | 74 | - **Comprehensive Benchmarks**: Includes SELECT, INSERT, UPDATE, DELETE, complex queries, stored procedures, and transaction handling. |
33 | 75 | - **Error Handling**: Each benchmark function is wrapped with error handling to ensure smooth execution. |
34 | 76 | - **Progress Messages**: Clear progress messages are printed during execution for better visibility. |
35 | 77 | - **Automated Setup and Cleanup**: The script automatically sets up and cleans up the database environment before and after the benchmarks. |
36 | 78 |
|
| 79 | +## Key Features of `perf-benchmarking.py` |
| 80 | +- **Statistical Analysis**: Multiple iterations with avg/min/max/stddev calculations |
| 81 | +- **Real-World Queries**: Tests against AdventureWorks2022 with production-like queries |
| 82 | +- **Automatic Import Resolution**: Correctly imports local `mssql_python` package |
| 83 | +- **Comprehensive Reporting**: Detailed comparison tables and performance summaries |
| 84 | +- **Speedup Calculations**: Clear indication of performance differences |
| 85 | + |
37 | 86 | ## Notes |
38 | 87 | - Ensure the database user has the necessary permissions to create and drop tables and stored procedures. |
39 | | -- The script uses permanent tables prefixed with `perfbenchmark_` for benchmarking purposes. |
40 | | -- A stored procedure named `perfbenchmark_stored_procedure` is created and used during the benchmarks. |
| 88 | +- The `bench_mssql.py` script uses permanent tables prefixed with `perfbenchmark_` for benchmarking purposes. |
| 89 | +- A stored procedure named `perfbenchmark_stored_procedure` is created and used during the benchmarks. |
| 90 | +- The `perf-benchmarking.py` script connects to AdventureWorks2022 and requires read permissions only. |
0 commit comments