ruby - sinatra vs grape 框架比较

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

内容简介: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)


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

查看所有标签

猜你喜欢:

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

Charlotte's Web

Charlotte's Web

E. B. White / Scholastic / 2004 / USD 0.01

This is the tale of how a little girl named Ferm, with the help of a friendly spider, saved her pig, Wilbur, from the usual fate of nice fat little pigs.一起来看看 《Charlotte's Web》 这本书的介绍吧!

在线进制转换器
在线进制转换器

各进制数互转换器

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具