Skip to content

Commit a8a9ea0

Browse files
FIX: Update and publish benchmark script (#152)
### Work Item / Issue Reference <!-- IMPORTANT: Please follow the PR template guidelines below. For mssql-python maintainers: Insert your ADO Work Item ID below (e.g. AB#37452) For external contributors: Insert Github Issue number below (e.g. #149) Only one reference is required - either GitHub issue OR ADO Work Item. --> <!-- mssql-python maintainers: ADO Work Item --> > [AB#38033](https://sqlclientdrivers.visualstudio.com/c6d89619-62de-46a0-8b46-70b92a84d85e/_workitems/edit/38033) <!-- External contributors: GitHub Issue --> > GitHub Issue: #<ISSUE_NUMBER> ------------------------------------------------------------------- ### Summary <!-- Insert your summary of changes below. Minimum 10 characters required. --> This pull request introduces a new `benchmarks` directory with a `README.md` file to guide users on how to run database performance benchmarks using `pyodbc` and `mssql_python`. The documentation provides detailed instructions and highlights the key features of the benchmark script. ### Documentation for Benchmarking: * [`benchmarks/README.md`](diffhunk://#diff-576c27794bae284efc278336a16d0649aaf599973a64d4b65dc67bc99bb7f000R1-R40): Added a comprehensive guide explaining the purpose of benchmarks, setup instructions, and how to run them using `richbench`. The guide also outlines key features of the `bench_mssql.py` script, such as support for various database operations, error handling, and automated setup/cleanup. <!-- ### PR Title Guide > For feature requests FEAT: (short-description) > For non-feature requests like test case updates, config updates , dependency updates etc CHORE: (short-description) > For Fix requests FIX: (short-description) > For doc update requests DOC: (short-description) > For Formatting, indentation, or styling update STYLE: (short-description) > For Refactor, without any feature changes REFACTOR: (short-description) > For release related changes, without any feature changes RELEASE: #<RELEASE_VERSION> (short-description) ### Contribution Guidelines External contributors: - Create a GitHub issue first: https://github.com/microsoft/mssql-python/issues/new - Link the GitHub issue in the "GitHub Issue" section above - Follow the PR title format and provide a meaningful summary mssql-python maintainers: - Create an ADO Work Item following internal processes - Link the ADO Work Item in the "ADO Work Item" section above - Follow the PR title format and provide a meaningful summary --> --------- Co-authored-by: Gaurav Sharma <sharmag@microsoft.com>
1 parent 627328c commit a8a9ea0

File tree

2 files changed

+706
-0
lines changed

2 files changed

+706
-0
lines changed

benchmarks/README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Benchmarks
2+
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+
5+
## Why Benchmarks?
6+
- To measure the efficiency of `pyodbc` and `mssql_python` in handling database operations.
7+
- To identify performance bottlenecks and optimize database interactions.
8+
- To ensure the reliability and scalability of the libraries under different workloads.
9+
10+
## How to Run Benchmarks
11+
1. **Set Up the Environment Variable**:
12+
- Ensure you have a running SQL Server instance.
13+
- 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;
16+
```
17+
18+
2. **Install Richbench - Benchmarking Tool**:
19+
- Install richbench :
20+
```cmd
21+
pip install richbench
22+
```
23+
24+
3. **Run the Benchmarks**:
25+
- Execute richbench from the parent folder (mssql-python) :
26+
```cmd
27+
richbench benchmarks
28+
```
29+
Results will be displayed in the terminal with detailed performance metrics.
30+
31+
## Key Features of `bench_mssql.py`
32+
- **Comprehensive Benchmarks**: Includes SELECT, INSERT, UPDATE, DELETE, complex queries, stored procedures, and transaction handling.
33+
- **Error Handling**: Each benchmark function is wrapped with error handling to ensure smooth execution.
34+
- **Progress Messages**: Clear progress messages are printed during execution for better visibility.
35+
- **Automated Setup and Cleanup**: The script automatically sets up and cleans up the database environment before and after the benchmarks.
36+
37+
## Notes
38+
- 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.

0 commit comments

Comments
 (0)