Created
April 22, 2019 13:41
-
-
Save ota42y/3ed68a2cb0dc7c98122bdfd1a696ab72 to your computer and use it in GitHub Desktop.
committee benchmark
This file contains hidden or 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 'net/http' | |
APPS = '/apps?page=1' | |
COUNT = 1000 | |
Benchmark.bm(6) do |r| | |
r.report "NotUse" do | |
COUNT.times do | |
req = Net::HTTP.new('localhost', 5678) | |
req.get(APPS) | |
end | |
end | |
r.report "Use" do | |
COUNT.times do | |
req = Net::HTTP.new('localhost', 6789) | |
req.get(APPS) | |
end | |
end | |
end |
This file contains hidden or 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 'net/http' | |
require 'json' | |
DEEP = '/deep' | |
COUNT = 1000 | |
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" | |
} | |
] | |
BODY = {data: BASE * 100}.to_json | |
Benchmark.bm(6) do |r| | |
r.report "NotUse" do | |
COUNT.times do | |
http = Net::HTTP.new('localhost', 5678) | |
req = Net::HTTP::Post.new(DEEP) | |
req["Content-Type"] = "application/json" | |
req.body = BODY | |
http.request(req) | |
end | |
end | |
r.report "Use" do | |
COUNT.times do | |
http = Net::HTTP.new('localhost', 6789) | |
req = Net::HTTP::Post.new(DEEP) | |
req["Content-Type"] = "application/json" | |
req.body = BODY | |
http.request(req) | |
end | |
end | |
end |
This file contains hidden or 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 "sinatra" | |
require "committee" | |
use Committee::Middleware::RequestValidation, schema_path: 'demo.yaml' | |
use Committee::Middleware::ResponseValidation, schema_path: 'demo.yaml' | |
#set :logging, nil | |
get "/apps" do | |
content_type :json | |
{ret: :apps}.to_json | |
end | |
post "/deep" do | |
content_type :json | |
{ret: :apps}.to_json | |
end |
This file contains hidden or 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 |
This file contains hidden or 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
# frozen_string_literal: true | |
source "https://rubygems.org" | |
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } | |
gem "committee" | |
gem "sinatra" | |
gem "pry" | |
gem "pry-byebug" | |
gem 'minitest' | |
gem 'rack-test' | |
gem 'rack-cors' |
This file contains hidden or 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
GEM | |
remote: https://rubygems.org/ | |
specs: | |
byebug (11.0.0) | |
coderay (1.1.2) | |
committee (3.0.1) | |
json_schema (~> 0.14, >= 0.14.3) | |
openapi_parser (>= 0.2.2) | |
rack (>= 1.5) | |
json_schema (0.20.4) | |
method_source (0.9.2) | |
minitest (5.11.3) | |
mustermann (1.0.3) | |
openapi_parser (0.2.3) | |
pry (0.12.2) | |
coderay (~> 1.1.0) | |
method_source (~> 0.9.0) | |
pry-byebug (3.7.0) | |
byebug (~> 11.0) | |
pry (~> 0.10) | |
rack (2.0.7) | |
rack-cors (1.0.3) | |
rack-protection (2.0.5) | |
rack | |
rack-test (1.1.0) | |
rack (>= 1.0, < 3) | |
sinatra (2.0.5) | |
mustermann (~> 1.0) | |
rack (~> 2.0) | |
rack-protection (= 2.0.5) | |
tilt (~> 2.0) | |
tilt (2.0.9) | |
PLATFORMS | |
ruby | |
DEPENDENCIES | |
committee | |
minitest | |
pry | |
pry-byebug | |
rack-cors | |
rack-test | |
sinatra | |
BUNDLED WITH | |
2.0.1 |
This file contains hidden or 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 "sinatra" | |
require "committee" | |
#use Committee::Middleware::RequestValidation, schema_path: 'demo.yaml' | |
#use Committee::Middleware::ResponseValidation, schema_path: 'demo.yaml' | |
#set :logging, nil | |
get "/apps" do | |
content_type :json | |
{ret: :apps}.to_json | |
end | |
post "/deep" do | |
content_type :json | |
{ret: :apps}.to_json | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.