Rails Micro Benchmarks!


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.


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


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


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


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

require_relative 'support/benchmark_rails.rb'

  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

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

admin = true

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


  admin = !admin

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



New results after calling to_a on User.all.


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


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


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.


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


Added mysql and postgres benchmarks.


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


Still needs to be fixed…