Skip to content

Instantly share code, notes, and snippets.

@nesquena
Created July 8, 2011 19:26
Show Gist options
  • Save nesquena/1072608 to your computer and use it in GitHub Desktop.
Save nesquena/1072608 to your computer and use it in GitHub Desktop.
require 'benchmark'
require 'active_support/all'
require 'httparty'
HOST = "http://listify-it.herokuapp.com"
def benchy(name, count=5)
result = Benchmark.realtime { count.times { HTTParty.get("#{HOST}/debug/#{name}") } } / count.to_f
"#{(result * 1000).round} ms average"
end
def bench_it(name, count=5)
benchy(name, count) # Warmup
3.times.map { benchy(name, count) }.inspect
end
########################################
# RESULTS
# bench_it(to_json) - ["33 ms average", "24 ms average", "36 ms average"]
# bench_it(rabl1) - ["36 ms average", "23 ms average", "43 ms average"]
# bench_it(rabl2) - ["41 ms average", "45 ms average", "42 ms average"]
########################################
get :to_json do
@lists = List.recent.includes(:users).limit(15)
@lists.to_json
end
get :rabl1 do
@lists = List.recent.includes(:users).limit(15)
render "lists/small"
end
get :rabl2 do
@lists = List.recent.includes(:users).limit(15)
render "lists/medium"
end
@nesquena
Copy link
Author

nesquena commented Jul 8, 2011

For 'medium' we purposely used extends and partial and added a lot more attributes to measure the performance impact

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment