Forum: Ruby ruby1.9 and ActiveRecord

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Andreas S. (Guest)
on 2009-04-23 02: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

Thanks in advance.

------ 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

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

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

#job = Job

data = "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.