Skip to content

Commit 01855f8

Browse files
committed
Merge branch 'saumya/pref-setup' of https://github.com/microsoft/mssql-python into saumya/pref-setup
2 parents dea7946 + e000808 commit 01855f8

File tree

3 files changed

+635
-11
lines changed

3 files changed

+635
-11
lines changed

benchmarks/README.md

Lines changed: 61 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,89 @@
22

33
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.
44

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+
513
## Why Benchmarks?
614
- To measure the efficiency of `pyodbc` and `mssql_python` in handling database operations.
715
- To identify performance bottlenecks and optimize database interactions.
816
- To ensure the reliability and scalability of the libraries under different workloads.
917

1018
## How to Run Benchmarks
19+
20+
### Running bench_mssql.py (Richbench Framework)
21+
1122
1. **Set Up the Environment Variable**:
1223
- Ensure you have a running SQL Server instance.
1324
- 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=your_database;UID=your_user;PWD=your_password;"
1627
```
1728

1829
2. **Install Richbench - Benchmarking Tool**:
19-
- Install richbench :
20-
```cmd
21-
pip install richbench
22-
```
30+
```bash
31+
pip install richbench
32+
```
2333

2434
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
2737
richbench benchmarks
2838
```
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
3072

3173
## Key Features of `bench_mssql.py`
3274
- **Comprehensive Benchmarks**: Includes SELECT, INSERT, UPDATE, DELETE, complex queries, stored procedures, and transaction handling.
3375
- **Error Handling**: Each benchmark function is wrapped with error handling to ensure smooth execution.
3476
- **Progress Messages**: Clear progress messages are printed during execution for better visibility.
3577
- **Automated Setup and Cleanup**: The script automatically sets up and cleans up the database environment before and after the benchmarks.
3678

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+
3786
## Notes
3887
- 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

Comments
 (0)