Rails Long Running Benchmarks


Benchmark Types
Show the last
Results
Compare

Activerecord/postgres scope all with default scope Graph (Number of iterations per second)

Activerecord/postgres scope all with default scope Graph (Allocated objects)

You can run this benchmark locally using the rubybench_runner gem:

gem install rubybench_runner
rubybench_runner run rails/bm_activerecord_scope_all_with_default_scope.rb
More details here.

Activerecord/postgres scope all with default scope Script View on Github

require 'bundler/setup'
require 'active_record'
require_relative 'support/benchmark_rails'

db_setup script: "bm_with_default_scope_setup.rb"

ActiveRecord::Base.establish_connection(ENV.fetch('DATABASE_URL'))
ActiveRecord::Migration.verbose = false

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

Benchmark.rails("activerecord/#{db_adapter}_scope_all_with_default_scope", time: 5) do
  str = ""
  User.select(:name, :email).each do |user|
    str << "name: #{user.name} email: #{user.email}\n"
  end
end