소스 검색

Merge pull request #8 from abevoelker/update-ruby-examples

Use map instead of side-effecting each for Ruby benchmarks
TechEmpower 12 년 전
부모
커밋
3376a97cf3
2개의 변경된 파일6개의 추가작업 그리고 8개의 파일을 삭제
  1. 3 4
      rails/app/controllers/hello_world_controller.rb
  2. 3 4
      sinatra/hello_world.rb

+ 3 - 4
rails/app/controllers/hello_world_controller.rb

@@ -4,13 +4,12 @@ class HelloWorldController < ApplicationController
   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

+ 3 - 4
sinatra/hello_world.rb

@@ -21,11 +21,10 @@ get '/json' do
 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