Forum: Ruby ruby1.9 and ActiveRecord

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
78a18d36dfae2b8bfd6483d854e67189?d=identicon&s=25 Andreas Sun (andreas_s)
on 2009-04-23 00:43
(Received via mailing list)
I wanted to switch my app from ruby 1.8 to 1.9 but I notice
ar-extensions' ActiveRecord#import takes longer. The code to demonstrate
it is attached. There is no significant time difference in both
variations in ruby 1.8 (I used fastercsv for 1.8). It looks like 1.9
issue, but first of all I'd appreciate if somebody can confirm this
behavior

Thanks in advance.
-andre


------ test_ar.rb -----
require 'ar-extensions'
require 'csv'

ActiveRecord::Base.establish_connection :adapter => 'sqlite3', :dbfile
=> ':memory:'
ActiveRecord::Schema.define do
  create_table 'jobs' do |t|
    t.column :xid, :integer
    t.column :user, :string
    t.column :time, :time
    t.column :duration, :integer
    t.column :machine, :string
    t.column :command, :string
  end
end

# This one is slow. Notice local variable "job"
job = Class.new ActiveRecord::Base do
  set_table_name 'jobs'
end

# This one is fast. Notice constant "Job"
#Job = Class.new ActiveRecord::Base do
#   set_table_name 'jobs'

#end
#job = Job

data = CSV.read "data.csv", :headers => false
 job.import %w{ xid user time duration machine command }, data,
:validate => false


# Fast one (with constant Job)
[lwe1:fx] time ruby19 test_ar.rb
-- create_table("jobs")
   -> 0.0701s
6.349u 0.231s 0:06.97 94.2%     0+0k 0+0io 0pf+0w

# Slow one (with local variable job)
[lwe1:fx] time ruby19 test_ar.rb
-- create_table("jobs")
   -> 0.0647s
27.533u 0.270s 0:28.08 99.0%    0+0k 0+0io 0pf+0w
This topic is locked and can not be replied to.