ruby - sinatra vs grape 框架比较

栏目: Ruby · 发布时间: 6年前

内容简介:sinatra 和 grape都是ruby 的api框架。性能上: sinatra大约是 grape的2倍。高判立下。$ ab -n 1000 -c 100 http://localhost:4567/hi?name=jim

sinatra 和 grape都是 ruby 的api框架。

性能上: sinatra大约是 grape的2倍。高判立下。

sinatra代码

require 'sinatra'
get '/hi' do
  "Put this in your pipe & smoke it!, name: #{params[:name]}"
end

$ ab -n 1000 -c 100 http://localhost:4567/hi?name=jim

Requests per second: 1629.18 [#/sec] (mean)

grape代码

require 'sinatra'
require 'grape'

class API < Grape::API
  format :json
  params do
    requires :name, type: String
    optional :number, type: String, regexp: /abc.*/
    optional :page, type: Integer
  end
  get :hello do
    {
      hello: "hello #{params[:name]}, #{params[:number]}"
    }
  end

  get :hi do
    {
      hi: 'good day!'
    }
  end

end

run API

$ ab -n 1000 -c 100 http://localhost:9292/hello.json?name=siwei

Requests per second: 647.96 [#/sec] (mean)

$ ab -n 1000 -c 100 http://localhost:9292/hi.json

Requests per second: 813.11 [#/sec] (mean)


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

APIs

APIs

Daniel Jacobson、Greg Brail、Dan Woods / O'Reilly Media / 2011-12-24 / USD 24.99

Many of the highest traffic sites get more than half of their traffic not through the browser but through the APIs they have created. Salesforce.com (more than 50%) and Twitter (more than 75% fall int......一起来看看 《APIs》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器