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)


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

查看所有标签

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

The Four

The Four

Scott Galloway / Portfolio / 2017-10-3 / USD 28.00

NEW YORK TIMES BESTSELLER USA TODAY BESTSELLER Amazon, Apple, Facebook, and Google are the four most influential companies on the planet. Just about everyone thinks they know how they got there.......一起来看看 《The Four》 这本书的介绍吧!

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

在线压缩/解压 JS 代码

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具