ruby - sinatra vs grape 框架比较

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

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


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

查看所有标签

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

Linux内核完全注释

Linux内核完全注释

赵炯 / 机械工业出版社 / 2005-8 / 42.00元

Linux内核完全注释,ISBN:9787111149682,作者:赵炯编著一起来看看 《Linux内核完全注释》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具

HEX HSV 转换工具
HEX HSV 转换工具

HEX HSV 互换工具