Sha256: cf0bce655eef7892f882f9fcf7801f469d97709550921bb98a6cf5382d58e2a8
Contents?: true
Size: 1.05 KB
Versions: 1
Compression:
Stored size: 1.05 KB
Contents
# frozen_string_literal: true require 'bundler/setup' require 'active_record' require 'activerecord-import' require File.expand_path('../../connect_db.rb', __FILE__) require File.expand_path('../../spec/models/user.rb', __FILE__) require 'active_record/pg_generate_series' require 'benchmark' RECORD_NUM = 10_000 User.delete_all GC.disable Benchmark.bm(36) do |x| x.report('iteration of ActiveRecord::Base#save') do RECORD_NUM.times do |i| user = User.new(name: "name#{i + 1}", age: i + 1, birth_date: Date.today + i + 1) user.save(validate: false) end end x.report('bulk insert(activerecord-import)') do users = RECORD_NUM.times.map do |i| User.new(name: "name#{i + 1}", age: i + 1, birth_date: Date.today + i + 1) end User.import(users) end x.report('active_record-pg_generate_series') do User.insert_using_generate_series(1, RECORD_NUM) do |sql| sql.name = raw("'name' || seq") sql.age = raw('seq') sql.birth_date = raw("'2000-01-01'::date + seq") end end end GC.enable User.delete_all
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
active_record-pg_generate_series-0.1.1 | bin/benchmark.rb |