Rails Micro Benchmarks!


#1

Starting this thread to get things going!

I’ve just added benchmarks for default_scope and the results are quite shocking that I’ll review it on my local machine tomorrow.


http://rubybench.org/rails/rails/releases?result_type=activerecord/sqlite3_finders_all

There are still some benchmarks that Kirs has written but I’ve yet to activate them yet.


#2

That does looks a bit odd, was expecting a regression in 4.2.0 not in 4.10


#3

@sam I have verified and am getting the same results on my local machine.


#4

require 'bundler/setup'
require 'rails'
require 'active_record'
require 'stackprof'

require_relative 'support/benchmark_rails.rb'

ActiveRecord::Base.establish_connection(
  adapter: 'sqlite3',
  database: ':memory:'
)

ActiveRecord::Migration.verbose = false

ActiveRecord::Schema.define do
  create_table :users, force: true do |t|
    t.string :name, :email
    t.boolean :admin
    t.timestamps null: false
  end
end

class User < ActiveRecord::Base
  default_scope { where(admin: true) }
end

admin = true

1000.times do
  attributes = {
    name: "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
    email: "foobar@email.com",
    admin: admin
  }

  User.create!(attributes)

  admin = !admin
end

# Benchmark.rails("activerecord/sqlite3_finders_all", time: 10) do
StackProf.run(mode: :cpu, out: 'after.dump') do
  100000.times do
    User.all
  end
end


#5

@sam

New results after calling to_a on User.all.


#6

clearly an anomaly on 3.2.4 its destroying the graph :slight_smile:


#7

Yea I noticed that and re-ran the benchmark again. Same results. We should investigate xD


#8

I just ran the benchmark on the local machine. Didn’t seem like there was anything wrong. User.all returns an array on Rails 3.2.4.


#9

We need some sort of solution here, if there is an outlier result graph should still be usable.


#10

Added mysql and postgres benchmarks.


#11

Hmm just noticed that the anomaly disappear… RubyBench - Long Running Ruby Benchmark


#12

Still needs to be fixed…