File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed
Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change 1+ require_relative './benchmarking_support'
2+ require_relative './app'
3+
4+ time = 10
5+ disable_gc = true
6+ ActiveModelSerializers . config . key_transform = :unaltered
7+ has_many_relationships = ( 0 ..60 ) . map do |i |
8+ HasManyRelationship . new ( id : i , body : 'ZOMG A HAS MANY RELATIONSHIP' )
9+ end
10+ has_one_relationship = HasOneRelationship . new (
11+ id : 42 ,
12+ first_name : 'Joao' ,
13+ last_name : 'Moura'
14+ )
15+ primary_resource = PrimaryResource . new (
16+ id : 1337 ,
17+ title : 'New PrimaryResource' ,
18+ virtual_attribute : nil ,
19+ body : 'Body' ,
20+ has_many_relationships : has_many_relationships ,
21+ has_one_relationship : has_one_relationship
22+ )
23+ serializer = PrimaryResourceSerializer . new ( primary_resource )
24+
25+ Benchmark . ams ( 'attributes' , time : time , disable_gc : disable_gc ) do
26+ attributes = ActiveModelSerializers ::Adapter ::Attributes . new ( serializer )
27+ attributes . as_json
28+ end
29+
30+ Benchmark . ams ( 'json_api' , time : time , disable_gc : disable_gc ) do
31+ json_api = ActiveModelSerializers ::Adapter ::JsonApi . new ( serializer )
32+ json_api . as_json
33+ end
34+
35+ Benchmark . ams ( 'json' , time : time , disable_gc : disable_gc ) do
36+ json = ActiveModelSerializers ::Adapter ::Json . new ( serializer )
37+ json . as_json
38+ end
You can’t perform that action at this time.
0 commit comments