Created
October 27, 2012 15:04
-
-
Save senny/3965012 to your computer and use it in GitHub Desktop.
Performance of ActiveRecord-Setters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create_table :numeric_data, :force => true do |t| | |
t.decimal :big_bank_balance, :precision => 15, :scale => 2 | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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