Skip to content

Commit

Permalink
Merge pull request #8 from abevoelker/update-ruby-examples
Browse files Browse the repository at this point in the history
Use map instead of side-effecting each for Ruby benchmarks
  • Loading branch information
TechEmpower committed Mar 28, 2013
2 parents abe639c + 5d7e843 commit 3376a97
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
7 changes: 3 additions & 4 deletions rails/app/controllers/hello_world_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ def json
end

def db
queries = params[:queries] || 1
queries = (params[:queries] || 1).to_i

results = []
(1..queries.to_i).each do
results = (1..queries).map do
# get a random row from the database, which we know has 10000
# rows with ids 1 - 10000
results << World.find(Random.rand(10000) + 1)
World.find(Random.rand(10000) + 1)
end
render :json => results
end
Expand Down
7 changes: 3 additions & 4 deletions sinatra/hello_world.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@ class World < ActiveRecord::Base
end

get '/db' do
queries = params[:queries] || 1
queries = (params[:queries] || 1).to_i

results = []
(1..queries.to_i).each do
results << World.find(Random.rand(10000) + 1)
results = (1..queries).map do
World.find(Random.rand(10000) + 1)
end

results.to_json
Expand Down

0 comments on commit 3376a97

Please sign in to comment.