Skip to content

Instantly share code, notes, and snippets.

@tomas-stefano
Created November 18, 2010 16:59
Show Gist options
  • Select an option

  • Save tomas-stefano/705274 to your computer and use it in GitHub Desktop.

Select an option

Save tomas-stefano/705274 to your computer and use it in GitHub Desktop.
Generate simple queries with Relation https://github.com/tomas-stefano/relation
10.000 Queries 0.030000 0.000000 0.030000 ( 0.031400)
100.000 Queries 0.300000 0.010000 0.310000 ( 0.307062)
1.000.000 Queries 3.070000 0.060000 3.130000 ( 3.150164)
A Little more complexity =p
10.000 Queries 0.090000 0.000000 0.090000 ( 0.086945)
100.000 Queries 0.840000 0.020000 0.860000 ( 0.857581)
1.000.000 Queries 8.360000 0.200000 8.560000 ( 8.568261)
bench_dir = File.expand_path(File.dirname(__FILE__))
$LOAD_PATH.unshift(File.join( bench_dir, '..', 'lib'))
require 'benchmark'
require 'relation'
@table = Relation::Table.new('users')
def simple_query!
@table.select('*').limit(1).to_sql # SELECT * from users LIMIT 1
end
def a_little_more_complexity!
@table.limit(1). \
where("name = 'tomas'"). \
having("email = 'tomas_stefano@testing.com'"). \
select('name', 'email', 'count(*)'). \
order("name, email"). \
to_sql
end
Benchmark.benchmark do |x|
x.report("10.000 Queries ") do
10_000.times do
simple_query!
end
end
x.report("100.000 Queries ") do
100_000.times do
simple_query!
end
end
x.report("1.000.000 Queries ") do
1_000_000.times do
simple_query!
end
end
puts
puts 'A Little more complexity =p'
puts
x.report("10.000 Queries ") do
10_000.times do
a_little_more_complexity!
end
end
x.report("100.000 Queries ") do
100_000.times do
a_little_more_complexity!
end
end
x.report("1.000.000 Queries ") do
1_000_000.times do
a_little_more_complexity!
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment