Skip to content

Instantly share code, notes, and snippets.

@mfazekas
Created December 14, 2014 23:27
Show Gist options
  • Save mfazekas/897f857e4367c94b771b to your computer and use it in GitHub Desktop.
Save mfazekas/897f857e4367c94b771b to your computer and use it in GitHub Desktop.
rr42_create_obj_with_serialized_perf
unless File.exist?('Gemfile')
File.write('Gemfile', <<-GEMFILE)
source 'https://rubygems.org'
gem 'rails', '4.1.8'
#gem 'rails', '4.2.0.rc3'
gem 'sqlite3'
gem 'pg'
gem 'byebug'
GEMFILE
system 'bundle'
end
require 'bundler'
Bundler.setup(:default)
require 'active_record'
require 'minitest/autorun'
require 'logger'
require 'byebug'
# This connection will do for database-independent bug reports.
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Schema.define do
create_table "dummy_items", force: true do |t|
t.string :data1
t.string :data2
t.string :data3
t.string :data4
t.integer :num
end
end
class DummyItem < ActiveRecord::Base
serialize :data1, Array
serialize :data2, Array
serialize :data3, Array
serialize :data4, Array
after_initialize :init
def init
self.num = 42
end
end
class PerfTest < Minitest::Test
def test_initialize
puts Benchmark.measure { 3000.times { DummyItem.new } }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment