Last active
May 13, 2020 21:29
-
-
Save ota42y/1a5fb27e31aa5868af307fd66f52878b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ruby 2.6.3、Mac Book Pro, Core i5 2.7GHz