Skip to content

Instantly share code, notes, and snippets.

@senny
Created October 27, 2012 15:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save senny/3965012 to your computer and use it in GitHub Desktop.
Save senny/3965012 to your computer and use it in GitHub Desktop.
Performance of ActiveRecord-Setters
user system total real
variable 1.590000 0.000000 1.590000 ( 1.599274)
AR 69.490000 2.440000 71.930000 ( 71.920999)
AR is 44.97 times slower.
create_table :numeric_data, :force => true do |t|
t.decimal :big_bank_balance, :precision => 15, :scale => 2
end
require "cases/helper"
class PerformanceTest < ActiveRecord::TestCase
class NumericData < ActiveRecord::Base; end
def test_active_record_setter_performance
require 'benchmark'
data = NumericData.new(:big_bank_balance => 0)
@big_bank_balance = BigDecimal.new('0')
n = 1_000_000
Benchmark.bm do |x|
x.report('variable') { n.times { |i| @big_bank_balance += i } }
x.report('AR') { n.times { |i| data.big_bank_balance += i } }
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment