Skip to content

Instantly share code, notes, and snippets.

@tiegz
Created January 25, 2012 23:17
Show Gist options
  • Save tiegz/1679603 to your computer and use it in GitHub Desktop.
Save tiegz/1679603 to your computer and use it in GitHub Desktop.
Rails 3 vs Grape benchmark
# config/routes.rb
mount MyGrapeAPI => "/grape_api"
namespace :api do
namespace :v1 do
resources :projects
end
end
#######################
##### RAILS 3 API #####
#######################
# app/controllers/api/v1/base_controller.rb
class Api::V1::BaseController < ActionController::Base
respond_to :json
end
# app/controllers/api/v1/projects_controller.rb
class Api::V1::ProjectsController < Api::V1::BaseController
def index
respond_with Project.new
end
end
#####################
##### GRAPE API #####
#####################
# app/middleware/my_grape_api.rb
class MyGrapeAPI < Grape::API
version 'v1'
resources :projects do
get "/" do
Project.new
end
end
end
# Apache Bench commands: 1000 requests, 50 concurrent requests
# ab -n 1000 -c 50 -g "grape_api.data" http://api.local/grape_api/v1/projects.json
# ab -n 1000 -c 50 -g "rails_3_api.data" http://api.local/api/v1/projects.json
@cubiic
Copy link

cubiic commented May 24, 2012

Can u share the local results please here so you can give us an indicator ?

@cubiic
Copy link

cubiic commented May 24, 2012

many thanks , cheers

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