File tree Expand file tree Collapse file tree 2 files changed +48
-0
lines changed Expand file tree Collapse file tree 2 files changed +48
-0
lines changed Original file line number Diff line number Diff line change 17
17
group :development do
18
18
gem 'appraisal'
19
19
gem 'benchmark-ips'
20
+ gem 'benchmark-memory'
20
21
gem 'guard'
21
22
gem 'guard-rspec'
22
23
gem 'guard-rubocop'
Original file line number Diff line number Diff line change
1
+ $LOAD_PATH. unshift ( File . join ( File . dirname ( __FILE__ ) , '..' , 'lib' ) )
2
+ require 'grape'
3
+ require 'benchmark/memory'
4
+
5
+ class VotingApi < Grape ::API
6
+ logger Logger . new ( STDOUT )
7
+
8
+ helpers do
9
+ def logger
10
+ VotingApi . logger
11
+ end
12
+ end
13
+
14
+ namespace 'votes' do
15
+ get do
16
+ logger
17
+ end
18
+ end
19
+ end
20
+
21
+ class PostApi < Grape ::API
22
+ mount VotingApi
23
+ end
24
+
25
+ class CommentAPI < Grape ::API
26
+ mount VotingApi
27
+ end
28
+
29
+ env = Rack ::MockRequest . env_for ( '/votes' , method : 'GET' )
30
+
31
+ Benchmark . memory do |api |
32
+ calls = 1000
33
+
34
+ api . report ( 'using Array' ) do
35
+ VotingApi . instance_variable_set ( :@setup , [ ] )
36
+ calls . times { PostApi . call ( env ) }
37
+ puts " setup size: #{ VotingApi . instance_variable_get ( :@setup ) . size } "
38
+ end
39
+
40
+ api . report ( 'using Set' ) do
41
+ VotingApi . instance_variable_set ( :@setup , Set . new )
42
+ calls . times { PostApi . call ( env ) }
43
+ puts " setup size: #{ VotingApi . instance_variable_get ( :@setup ) . size } "
44
+ end
45
+
46
+ api . compare!
47
+ end
You can’t perform that action at this time.
0 commit comments