-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathremounting.rb
49 lines (38 loc) · 958 Bytes
/
remounting.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# frozen_string_literal: true
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
require 'grape'
require 'benchmark/memory'
class VotingApi < Grape::API
logger Logger.new($stdout)
helpers do
def logger
VotingApi.logger
end
end
namespace 'votes' do
get do
logger
end
end
end
class PostApi < Grape::API
mount VotingApi
end
class CommentAPI < Grape::API
mount VotingApi
end
env = Rack::MockRequest.env_for('/votes', method: Rack::GET)
Benchmark.memory do |api|
calls = 1000
api.report('using Array') do
VotingApi.instance_variable_set(:@setup, [])
calls.times { PostApi.call(env) }
puts " setup size: #{VotingApi.instance_variable_get(:@setup).size}"
end
api.report('using Set') do
VotingApi.instance_variable_set(:@setup, Set.new)
calls.times { PostApi.call(env) }
puts " setup size: #{VotingApi.instance_variable_get(:@setup).size}"
end
api.compare!
end