Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
require 'benchmark'
require "committee"
COUNT = 10000
noop = Proc.new {[200, {}, ["hello"]]}
middleware = Committee::Middleware::RequestValidation.new(noop, schema_path: 'demo.yaml')
# warmup
request = Rack::MockRequest.new(middleware)
noop_request = Rack::MockRequest.new(noop)
COUNT.times { noop_request.get('/apps?page=1') }
COUNT.times { request.get('/apps?page=1') }
# small test
::Benchmark.bm(6) do |r|
r.report "NotUse" do
COUNT.times { noop_request.get('/apps?page=1') }
end
r.report "Use" do
COUNT.times { request.get('/apps?page=1') }
end
end
# big test
BASE = [
{
"a"=>"a", "b"=>"b", "c"=>"c", "d"=>"d", "e"=>"e", "f"=>"f", "g"=>"g",
"h"=>"h", "i"=>"i", "j"=>"j", "k"=>"k", "l"=>"l", "m"=>"m", "n"=>"n",
"o"=>"o", "p"=>"p", "q"=>"q", "r"=>"r", "s"=>"s", "t"=>"t", "u"=>"u",
"v"=>"v", "w"=>"w", "x"=>"x", "y"=>"y", "z"=>"z"
}
]
N_BODY = {data: BASE * 10}.to_json
::Benchmark.bm(6) do |r|
r.report "NotUse" do
COUNT.times { noop_request.post('/deep', params: N_BODY, CONTENT_TYPE: 'application_json') }
end
r.report "Use" do
COUNT.times { request.post('/deep', params: N_BODY, CONTENT_TYPE: 'application_json') }
end
end
BODY = {data: BASE * 100}.to_json
::Benchmark.bm(6) do |r|
r.report "NotUse" do
COUNT.times { noop_request.post('/deep', params: BODY, CONTENT_TYPE: 'application_json') }
end
r.report "Use" do
COUNT.times { request.post('/deep', params:BODY, CONTENT_TYPE: 'application_json') }
end
end
openapi: 3.0.0
info:
title: Sample API
version: 0.1.0
paths:
"/normal":
get:
description: get app names by array
parameters:
- name: page
in: query
required: true
description: specific page setting
schema:
type: integer
responses:
'200':
description: return array include strings
content:
'application/json':
schema:
description: app name stirngs
type: array
items:
type: string
"/deep":
post:
description: deep data test
requestBody:
content:
'application/json':
schema:
type: object
properties:
data:
type: array
items:
type: object
properties:
a:
type: string
b:
type: string
c:
type: string
d:
type: string
e:
type: string
f:
type: string
g:
type: string
h:
type: string
i:
type: string
j:
type: string
k:
type: string
l:
type: string
m:
type: string
n:
type: string
o:
type: string
p:
type: string
q:
type: string
r:
type: string
s:
type: string
t:
type: string
u:
type: string
v:
type: string
w:
type: string
x:
type: string
y:
type: string
z:
type: string
responses:
'200':
description: return array include strings
content:
'application/json':
schema:
type: object
properties:
ret:
type: string
@ota42y

This comment has been minimized.

Copy link
Owner Author

commented May 15, 2019

             user     system      total        real
NotUse   0.284922   0.001665   0.286587 (  0.289507)
Use      0.856720   0.007152   0.863872 (  0.883071)
             user     system      total        real
NotUse   0.254919   0.001445   0.256364 (  0.257958)
Use      1.675945   0.006960   1.682905 (  1.689440)
             user     system      total        real
NotUse   0.258484   0.001223   0.259707 (  0.261796)
Use      7.415056   3.108207  10.523263 ( 10.625856)

Ruby 2.6.3、Mac Book Pro, Core i5 2.7GHz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.