-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from pocke/Add_benchmark_script
Add benchmark script
- Loading branch information
Showing
5 changed files
with
76 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,3 +14,5 @@ gem "rubocop", "~> 1.21", require: false | |
gem 'steep', require: false | ||
|
||
gem 'sqlite3' | ||
|
||
gem 'benchmark-ips' |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
require 'active_record' | ||
require 'benchmark/ips' | ||
|
||
ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:") | ||
ActiveRecord::Base.logger = Logger.new(File::NULL) | ||
ActiveRecord::Schema.define do | ||
create_table :posts, force: true do |t| | ||
t.string :title, null: false | ||
t.string :state, null: false | ||
t.integer :comments_count, default: 0 | ||
t.integer :likes_count, default: 0 | ||
end | ||
end | ||
|
||
class Post < ActiveRecord::Base | ||
end | ||
|
||
100.times do |i| | ||
Post.create!(title: "title#{i}", state: i.odd? ? 'draft' : 'published', comments_count: i, likes_count: i) | ||
end | ||
|
||
Benchmark.ips do |x| | ||
x.report("without where") { Post.all.to_sql } | ||
x.report('with single condition') { Post.where(title: 'title1').to_sql } | ||
x.report('with multiple condition') { Post.where(state: 'draft', comments_count: ..42, likes_count: ..43).to_sql } | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
require 'active_record' | ||
require 'benchmark/ips' | ||
|
||
ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:") | ||
ActiveRecord::Base.logger = Logger.new(File::NULL) | ||
ActiveRecord::Schema.define do | ||
create_table :posts, force: true do |t| | ||
t.string :title, null: false | ||
t.string :state, null: false | ||
t.integer :comments_count, default: 0 | ||
t.integer :likes_count, default: 0 | ||
end | ||
end | ||
|
||
class Post < ActiveRecord::Base | ||
end | ||
|
||
Benchmark.ips do |x| | ||
x.report("without where") { Post.all.to_sql } | ||
x.report('with single condition') { Post.where(title: 'hello').to_sql } | ||
x.report('with multiple condition') { Post.where(title: 'hello', state: 'draft', comments_count: 42, likes_count: 43).to_sql } | ||
end |