Skip to content

Instantly share code, notes, and snippets.

@logicalgroove
Last active December 8, 2023 23:18
Show Gist options
  • Save logicalgroove/a5189a7e7794fd41c34cc87602fb5bca to your computer and use it in GitHub Desktop.
Save logicalgroove/a5189a7e7794fd41c34cc87602fb5bca to your computer and use it in GitHub Desktop.
SPROC benchmark
# Prerequisite:
# gem install tiny_tds
require 'tiny_tds'
require 'benchmark'
# Database connection parameters
server = 'your_server'
database = 'your_database'
username = 'your_username'
password = 'your_password'
# Stored procedure names
stored_procedure_1 = 'your_stored_procedure_1'
stored_procedure_2 = 'your_stored_procedure_2'
# SQL to execute the stored procedures
sql1 = "EXEC #{stored_procedure_1}"
sql2 = "EXEC #{stored_procedure_2}"
# Create a database connection
client = TinyTds::Client.new(username: username, password: password, host: server, database: database)
# Benchmarking
Benchmark.bm do |x|
x.report("Stored Procedure 1: ") do
# Run the first stored procedure multiple times (e.g., 10 times)
10.times { client.execute(sql1).do }
end
x.report("Stored Procedure 2: ") do
# Run the second stored procedure multiple times (e.g., 10 times)
10.times { client.execute(sql2).do }
end
end
# Close the database connection
client.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment