This repo contains 2 version of rails: 5.0.7.2 and 5.1.7. The idea is to prepare them with minimum exact configuration for both versions to compare performance of simple command.
Testable snippet to load 2 one to many relationships, with preload via .includes()
. Returns median time spent on execution of one line product.variants.each { |v| v.option_values.first.name }
.
begin
repeat_amount = 200
product = Product.includes(variants: :option_values).find_by!(catalog_number: 'G640')
bar = ProgressBar.new(repeat_amount)
timings = repeat_amount.times.map do
time = Benchmark.realtime do
product.variants.each { |v| v.option_values.first.name }
end
bar.increment!
time
end
timings.sort[timings.size / 2]
end
- Clone and open folder
git clone [email protected]:sdtechdev/rails-5.1-performance-test.git && cd rails-5.1-performance-test
- Make sure ruby 2.6.1 installed. Not sure if it's version is important, but this version I used when tested performance.
- Both apps expect postgres running on host
postgres
and usernamepostgres
, without password - Setup 5.0.7.2
cd rails5_0_7_2 && bundle && bundle exec rails db:create db:structure:load db:seed
- Open console
bundle exec rails c
and run snippet from the beginning of this readme. Note down the time you've got. - Close console
exit
and go back to repo root foldercd ../
- Setup 5.1.7
cd rails5_1_7 && bundle && bundle exec rails db:create db:structure:load db:seed
- Open console
bundle exec rails c
and run snippet from the beginning of this readme. Note down the time you've got. - Now compare 2 numbers.
I tested it on my local machine, 5.1 version performance roughly ~40 times worse than 5.0 version performance. I have no idea if I did something wrong or there is some "specific" added in 5.1. Please let me know if you find anything. Cheers.
5.0: 0.0015s
5.1: 0.0787s
5.2: 0.0388s
6.0: 0.0421s
- Open root repo folder
- Install needed rails version, for example
gem install rails -v 5.2.4.1 --no-document
- Create new app
rails _5.2.4.1_ new rails5_2_4_1 --skip-bundle --database=postgresql --skip-git
- Prepare database.yml
host: postgres username: postgres
cp -R rails5_0_7_2/db/seeds rails5_2_4_1/db && cp rails5_0_7_2/db/seeds.rb rails5_2_4_1/db && cp rails5_0_7_2/db/structure.sql rails5_2_4_1/db && cp -R rails5_0_7_2/app/models/*.rb rails5_2_4_1/app/models
- add
config.active_record.schema_format = :sql
toconfig/application.rb
- add to Gemfile
gem 'pry-rails' gem 'progress_bar'