performance/cache_runner.rb in identity_cache-0.0.4 vs performance/cache_runner.rb in identity_cache-0.0.5
- old
+ new
@@ -16,15 +16,15 @@
require File.dirname(__FILE__) + '/../test/helpers/active_record_objects'
require File.dirname(__FILE__) + '/../test/helpers/database_connection'
require File.dirname(__FILE__) + '/../test/helpers/cache'
def create_record(id)
- r = Record.new(id)
+ Item.new(id)
end
def database_ready(count)
- Record.where(:id => (1..count)).count == count
+ Item.where(:id => (1..count)).count == count
rescue
false
end
def create_database(count)
@@ -33,25 +33,25 @@
a.setup_models
DatabaseConnection.setup
# set up associations
- Record.cache_has_one :associated
- Record.cache_has_many :associated_records, :embed => true
- Record.cache_has_many :normalized_associated_records, :embed => false
- Record.cache_index :title, :unique => :true
+ Item.cache_has_one :associated
+ Item.cache_has_many :associated_records, :embed => true
+ Item.cache_has_many :normalized_associated_records, :embed => false
+ Item.cache_index :title, :unique => :true
AssociatedRecord.cache_has_many :deeply_associated_records, :embed => true
return if database_ready(count)
puts "Database not ready for performance testing, generating records"
DatabaseConnection.drop_tables
DatabaseConnection.create_tables
- existing = Record.all
+ existing = Item.all
(1..count).to_a.each do |i|
unless existing.any? { |e| e.id == i }
- a = Record.new
+ a = Item.new
a.id = i
a.associated = AssociatedRecord.new(name: "Associated for #{i}")
a.associated_records
(1..5).each do |j|
a.associated_records << AssociatedRecord.new(name: "Has Many #{j} for #{i}")
@@ -75,11 +75,11 @@
end
class FindRunner < CacheRunner
def run
(1..@count).each do |i|
- ::Record.find(i)
+ ::Item.find(i)
end
end
end
module MissRunner
@@ -91,11 +91,11 @@
class FetchMissRunner < CacheRunner
include MissRunner
def run
(1..@count).each do |i|
- rec = ::Record.fetch(i)
+ rec = ::Item.fetch(i)
rec.fetch_associated
rec.fetch_associated_records
end
end
end
@@ -103,11 +103,11 @@
class DoubleFetchMissRunner < CacheRunner
include MissRunner
def run
(1..@count).each do |i|
- rec = ::Record.fetch(i)
+ rec = ::Item.fetch(i)
rec.fetch_associated
rec.fetch_associated_records
rec.fetch_normalized_associated_records
end
end
@@ -115,22 +115,22 @@
module HitRunner
def prepare
IdentityCache.cache.clear
(1..@count).each do |i|
- rec = ::Record.fetch(i)
+ rec = ::Item.fetch(i)
rec.fetch_normalized_associated_records
end
end
end
class FetchHitRunner < CacheRunner
include HitRunner
def run
(1..@count).each do |i|
- rec = ::Record.fetch(i)
+ rec = ::Item.fetch(i)
# these should all be no cost
rec.fetch_associated
rec.fetch_associated_records
end
end
@@ -139,14 +139,13 @@
class DoubleFetchHitRunner < CacheRunner
include HitRunner
def run
(1..@count).each do |i|
- rec = ::Record.fetch(i)
+ rec = ::Item.fetch(i)
# these should all be no cost
rec.fetch_associated
rec.fetch_associated_records
rec.fetch_normalized_associated_records
end
end
end
-