Created
August 1, 2017 01:05
-
-
Save metaskills/f8a7e0ee2e7f5abeac70a14afc478816 to your computer and use it in GitHub Desktop.
Simple SQL Server & PG Rails Benchmarks.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env ruby | |
| require 'benchmark' | |
| require 'bundler/inline' | |
| gemfile true do | |
| source 'https://rubygems.org' | |
| gem 'activerecord-sqlserver-adapter', ENV['VER_AR'] || '~> 5.1.0' | |
| gem 'tiny_tds', ENV['VER_TTDS'] || '~> 2.0.0' | |
| gem 'pg' | |
| end | |
| puts 'Connecting...' | |
| if ENV['PG'] | |
| ActiveRecord::Base.establish_connection adapter: 'postgresql', | |
| database: 'postgres', | |
| schema_search_path: 'public' | |
| else | |
| ActiveRecord::Base.establish_connection adapter: 'sqlserver', | |
| username: 'sa', | |
| password: ENV['SA_PASSWORD'], | |
| host: 'localhost' | |
| end | |
| puts "Drop and create new 'benchmark' database..." | |
| ActiveRecord::Base.connection.drop_database('benchmark') rescue nil | |
| ActiveRecord::Base.connection.create_database('benchmark') | |
| ActiveRecord::Base.connection.use_database('benchmark') unless ENV['PG'] | |
| ActiveRecord::Schema.define do | |
| create_table :fills, force: true do |t| | |
| t.belongs_to :order, null: false | |
| t.belongs_to :contract, null: false | |
| t.string :tt_order_id | |
| t.string :fill_key | |
| t.datetime :transact_time | |
| t.string :tt_username, null: false | |
| t.integer :quantity, null: false | |
| t.decimal :price, precision: 23, scale: 10, null: false | |
| t.integer :side, null: false | |
| t.string :fft2 | |
| t.integer :multi_leg_reporting_type, null: false | |
| t.timestamps null: false | |
| end | |
| end | |
| class Fill < ActiveRecord::Base ; end | |
| ActiveRecord::Base.logger = nil | |
| SIZE = 3000 | |
| SAMPLES = 5 | |
| def new_fill | |
| Fill.new side: 50, multi_leg_reporting_type: 49, | |
| contract_id: 1, quantity: 10, price: 100, | |
| tt_username: '123456', fill_key: SecureRandom.hex(3), | |
| transact_time: DateTime.now, order_id: 12 | |
| end | |
| samples = [] | |
| puts "Running benchmark...\n" | |
| SAMPLES.times.each do |i| | |
| time = Benchmark.realtime do |x| | |
| SIZE.times.each { new_fill.save! } | |
| end | |
| samples << time | |
| puts "#{i}: #{time}" | |
| end | |
| puts "A: #{samples.sum / SAMPLES}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ VER_AR=5.1.0 ruby ssbm.rb | |
| 0: 13.127322000000277 | |
| 1: 13.23479099999986 | |
| 2: 13.281009999999696 | |
| 3: 13.10219799999959 | |
| 4: 14.472125999999662 | |
| A: 13.443489399999816 | |
| $ PG=1 VER_AR=5.1.0 ruby ssbm.rb | |
| 0: 4.321280000000115 | |
| 1: 4.276819000000614 | |
| 2: 4.2964109999993525 | |
| 3: 4.322815999999875 | |
| 4: 4.3014069999999265 | |
| A: 4.303746599999977 | |
| $ VER_AR=4.2.0 ruby ssbm.rb | |
| 0: 12.59582599999976 | |
| 1: 12.267745000000104 | |
| 2: 12.348552000000382 | |
| 3: 13.87474900000052 | |
| 4: 13.527014999999665 | |
| A: 12.922777400000086 | |
| $ PG=1 VER_AR=4.2.0 ruby ssbm.rb | |
| 0: 4.275915000000168 | |
| 1: 4.3923869999998715 | |
| 2: 4.367001999999957 | |
| 3: 4.443519000000379 | |
| 4: 4.213646000000153 | |
| A: 4.338493800000106 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment