Skip to content

Instantly share code, notes, and snippets.

@pauldruziak
Created November 17, 2009 17:13
Show Gist options
  • Save pauldruziak/237069 to your computer and use it in GitHub Desktop.
Save pauldruziak/237069 to your computer and use it in GitHub Desktop.
#Для 1100 записів
[~/Projects/test2] ./script/performance/benchmarker 10 "Record.test_select" "Record.test_select2" "Record.test_select3" "Record.test_select4"
user system total real
#1 0.000000 0.000000 0.000000 ( 0.112709)
#2 0.110000 0.000000 0.110000 ( 0.168085)
#3 0.000000 0.000000 0.000000 ( 0.068406)
#4 4.620000 0.030000 4.650000 ( 6.498799)
[~/Projects/test2] ./script/performance/benchmarker 100 "Record.test_select" "Record.test_select2" "Record.test_select3" "Record.test_select4"
user system total real
#1 0.050000 0.010000 0.060000 ( 0.935885)
#2 1.320000 0.010000 1.330000 ( 2.005846)
#3 0.090000 0.010000 0.100000 ( 0.459577)
#4 45.540000 0.170000 45.710000 ( 66.452645)
#Для 11100 записів
[~/Projects/test2] ./script/performance/benchmarker 10 "Record.test_select" "Record.test_select2" "Record.test_select3" "Record.test_select5"
user system total real
#1 0.000000 0.000000 0.000000 ( 0.928129)
#2 1.280000 0.010000 1.290000 ( 1.908505)
#3 0.000000 0.010000 0.010000 ( 0.186427)
#4 0.020000 0.000000 0.020000 ( 0.020361)
[~/Projects/test2] ./script/performance/benchmarker 100 "Record.test_select" "Record.test_select2" "Record.test_select3" "Record.test_select5"
user system total real
#1 0.050000 0.000000 0.050000 ( 9.129972)
#2 13.030000 0.060000 13.090000 ( 19.909641)
#3 0.110000 0.000000 0.110000 ( 2.104700)
#4 0.070000 0.010000 0.080000 ( 0.230101)
[~/Projects/test2]
class Record < ActiveRecord::Base
def self.test_select
Record.first(:order => 'RAND() * records.weight DESC')
end
def self.test_select2
records = Record.find(:all, :select => 'id', :order => 'records.weight DESC')
Record.find(records[(rand()*records.count).to_i])
end
def self.test_select3(weight = 5)
Record.first(:conditions => [ "id >= ?", (rand()*Record.last.id).to_i], :order => 'records.weight DESC')
end
def self.test_select4
records = Record.all(:select => 'id, weight')
records_arr = []
records.each do |r|
r.weight.times{records_arr << r.id}
end
Record.find(records_arr[rand()*records_arr.size])
end
def self.test_select5
Record.find((rand*Record.count).to_i, :order => 'records.weight DESC')
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment