Skip to content

Instantly share code, notes, and snippets.

@syrnick
Created January 5, 2011 23:15
Show Gist options
  • Save syrnick/767201 to your computer and use it in GitHub Desktop.
Save syrnick/767201 to your computer and use it in GitHub Desktop.
# Trying to replicate performance issues with DM 1.0
# DM 0.10.2 -> 1.230000 0.110000 1.340000 ( 2.535200)
# DM 1.0.2 -> 3.080000 0.190000 3.270000 ( 4.842546)
#
require 'rubygems'
require 'dm-core'
require 'dm-migrations'
require 'dm-migrations/migration_runner'
require 'dm-timestamps'
require 'benchmark'
#DataMapper::Logger.new($stdout, :debug)
DataMapper.setup(:default, 'postgres://localhost/dm_perf_test') # createdb test
class Course
include DataMapper::Resource
property :id, Serial
property :name, String
has n, :exams
end
class Exam
include DataMapper::Resource
property :id, Serial
property :course_id, Serial
belongs_to :course
end
DataMapper::MigrationRunner.migration( 1, :create_courses ) do
up do
create_table :courses do
column :id, Integer, :serial => true
column :name, String, :size => 50
end
create_index(:courses, :id)
create_table :exams do
column :id, Integer, :serial => true
column :course_id, Integer
end
create_index(:exams, :id)
create_index(:exams, :course_id)
end
down do
drop_table :exams
drop_table :courses
end
end
DataMapper::MigrationRunner.migrate_up!
timing = Benchmark.measure do
1000.times do |i|
course = Course.create(:name =>"Ruby #{i}")
Exam.create(:course => course)
end
end
puts timing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment