Skip to content

Instantly share code, notes, and snippets.

@kamipo
Last active June 1, 2019 14:03
Show Gist options
  • Save kamipo/1ddad2235073f508637bf9a72d64bb83 to your computer and use it in GitHub Desktop.
Save kamipo/1ddad2235073f508637bf9a72d64bb83 to your computer and use it in GitHub Desktop.
# frozen_string_literal: true
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
gem "rails", github: "rails/rails"
gem "sqlite3"
gem "benchmark-ips"
gem "allocation_tracer"
end
require "active_record"
ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:")
ActiveRecord::Schema.define do
create_table :users, force: true do |t|
t.string :name
t.timestamps null: false
end
end
class User < ActiveRecord::Base
end
ObjectSpace::AllocationTracer.setup(%i{path line type})
pp ObjectSpace::AllocationTracer.trace {
1_000.times { User.create }
}.select { |k, _| k[2] == :T_ARRAY && k[0].end_with?("timestamp.rb") }
User.delete_all
Benchmark.ips do |x|
x.report("User.create * 10") { User.transaction { 10.times { User.create } } }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment