From 5d3ecb2f1607bbe17d80a5a4147d4f601de52b5c Mon Sep 17 00:00:00 2001 From: Benjamin Fleischer Date: Thu, 12 Oct 2017 23:37:34 -0500 Subject: [PATCH 01/13] Consistent records --- benchmarks/serialization_libraries/support/bench_helper.rb | 7 ++++--- benchmarks/serialization_libraries/support/rails.rb | 3 +++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/benchmarks/serialization_libraries/support/bench_helper.rb b/benchmarks/serialization_libraries/support/bench_helper.rb index 9ad2ab8c..0b37cccc 100644 --- a/benchmarks/serialization_libraries/support/bench_helper.rb +++ b/benchmarks/serialization_libraries/support/bench_helper.rb @@ -13,12 +13,13 @@ module BenchHelper posts: 20 } - u = User.create(first_name: 'Diana', last_name: 'Prince', birthday: 3000.years.ago) + anchor_time = Time.new(2017,7,1).utc + user = User.create(first_name: 'Diana', last_name: 'Prince', birthday: anchor_time, created_at: anchor_time, updated_at: anchor_time) data_config[:posts].times do - p = Post.create(user_id: u.id, title: 'Some Post', body: 'awesome content') + post = Post.create(user_id: user.id, title: 'Some Post', body: 'awesome content', created_at: anchor_time, updated_at: anchor_time) data_config[:comments_per_post].times do - Comment.create(author: 'me', comment: 'nice blog', post_id: p.id) + Comment.create(author: 'me', comment: 'nice blog', post_id: post.id, created_at: anchor_time, updated_at: anchor_time) end end end diff --git a/benchmarks/serialization_libraries/support/rails.rb b/benchmarks/serialization_libraries/support/rails.rb index 94ef7cda..eef52abb 100644 --- a/benchmarks/serialization_libraries/support/rails.rb +++ b/benchmarks/serialization_libraries/support/rails.rb @@ -36,14 +36,17 @@ class ApplicationRecord < ActiveRecord::Base end class Comment < ApplicationRecord + default_scope { order(:id) } belongs_to :post end class Post < ApplicationRecord + default_scope { order(:id) } has_many :comments belongs_to :user end class User < ApplicationRecord + default_scope { order(:id) } has_many :posts end From 919feafa0a2fa283dec009aed087ebe33e7a2099 Mon Sep 17 00:00:00 2001 From: Benjamin Fleischer Date: Thu, 12 Oct 2017 23:38:06 -0500 Subject: [PATCH 02/13] Clarify code a bit --- .../serialization_libraries/support/bench_helper.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/benchmarks/serialization_libraries/support/bench_helper.rb b/benchmarks/serialization_libraries/support/bench_helper.rb index 0b37cccc..a512303b 100644 --- a/benchmarks/serialization_libraries/support/bench_helper.rb +++ b/benchmarks/serialization_libraries/support/bench_helper.rb @@ -38,10 +38,14 @@ module BenchHelper ) end - def render_data(data, render_gem) - return render_with_ams(data) if render_gem == :ams + # protected - render_with_jsonapi_rb(data) + def render_data(data, render_gem) + case render_gem + when :ams then render_with_ams(data) + when :jsonapi_rb then render_with_jsonapi_rb(data) + else fail ArgumentError, "Cannot render unknown gem '#{render_gem.inspect}'" + end end def render_with_ams(data) From 6c90fc98c1acb381846ba5e4c4376a58db219d66 Mon Sep 17 00:00:00 2001 From: Benjamin Fleischer Date: Thu, 12 Oct 2017 23:54:15 -0500 Subject: [PATCH 03/13] Turn off (slow) AMS case transform MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ``` $ bundle exec ruby benchmark.rb -- create_table("comments", {:force=>:cascade}) -> 0.0127s -- create_table("posts", {:force=>:cascade}) -> 0.0030s -- create_table("users", {:force=>:cascade}) -> 0.0018s Warming up -------------------------------------- ams 1.000 i/100ms jsonapi-rb 4.000 i/100ms ams eager 2.000 i/100ms jsonapi-rb eager 9.000 i/100ms Calculating ------------------------------------- ams 16.572 (± 1.4%) i/s - 164.000 in 10.003051s jsonapi-rb 45.722 (± 0.9%) i/s - 460.000 in 10.084399s ams eager 21.037 (± 0.8%) i/s - 212.000 in 10.099436s jsonapi-rb eager 97.010 (± 1.3%) i/s - 972.000 in 10.069614s with 95.0% confidence Comparison: jsonapi-rb eager: 97.0 i/s jsonapi-rb : 45.7 i/s - 2.12x (± 0.03) slower ams eager: 21.0 i/s - 4.61x (± 0.07) slower ams : 16.6 i/s - 5.85x (± 0.11) slower with 95.0% confidence Calculating ------------------------------------- ams 3.793M memsize ( 185.000k retained) 44.737k objects ( 2.549k retained) 50.000 strings ( 40.000 retained) jsonapi-rb 1.873M memsize ( 0.000 retained) 21.424k objects ( 0.000 retained) 50.000 strings ( 0.000 retained) ams eager 2.923M memsize ( 180.848k retained) 34.285k objects ( 2.433k retained) 50.000 strings ( 46.000 retained) jsonapi-rb eager 899.226k memsize ( 0.000 retained) 9.485k objects ( 0.000 retained) 50.000 strings ( 0.000 retained) Comparison: jsonapi-rb eager: 899226 allocated jsonapi-rb : 1873384 allocated - 2.08x more ams eager: 2922890 allocated - 3.25x more ams : 3792800 allocated - 4.22x more ``` --- benchmarks/serialization_libraries/benchmark.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/benchmarks/serialization_libraries/benchmark.rb b/benchmarks/serialization_libraries/benchmark.rb index 7d6830e8..93dbef17 100644 --- a/benchmarks/serialization_libraries/benchmark.rb +++ b/benchmarks/serialization_libraries/benchmark.rb @@ -3,6 +3,8 @@ Bundler.require(*Rails.groups) ActiveRecord::Base.logger = nil ActiveModelSerializers.logger = nil +ActiveModelSerializers.config.adapter = :json_api +ActiveModelSerializers.config.key_transform = :unaltered require './support/rails' require './support/bench_helper' From d0ef3d1c89b9d68f46a16ef49b5b31ed91a22abc Mon Sep 17 00:00:00 2001 From: Benjamin Fleischer Date: Fri, 13 Oct 2017 17:53:04 -0500 Subject: [PATCH 04/13] Remove sqlite db from version control --- .gitignore | 1 + .../support/bench.sqlite3 | Bin 51200 -> 0 bytes 2 files changed, 1 insertion(+) delete mode 100644 benchmarks/serialization_libraries/support/bench.sqlite3 diff --git a/.gitignore b/.gitignore index 5dc5c1bd..dcf7035f 100644 --- a/.gitignore +++ b/.gitignore @@ -32,3 +32,4 @@ tags Icon? ehthumbs.db Thumbs.db +*.sqlite3 diff --git a/benchmarks/serialization_libraries/support/bench.sqlite3 b/benchmarks/serialization_libraries/support/bench.sqlite3 deleted file mode 100644 index a886ae03d1c5ef890c30e9c467f3e573c7cd4678..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 51200 zcmeI5O>7&-6~}jXBr|g2#BO6zvL$OxSu$l=)P8>`A2Myr8`(0Y$m`Z_(GY8KW3!b= zg`|}f=taq)ITZz(Q-K0K6h;sP2#`yB>Zzv!1&SO36i9%gm-b}9MbU#31bs8RR4IF8 z(koY%i$~}^QTyNh&+JdT+*!_Wc9ADu^c3T1a_K0b{F36_Thkig?5&?Azxc(WeX z>Jk|5jm&!_Sh!lPH|p8v2pJTYsw*pDrBPp?dY0@L$UX8ea)Jk7@oEMKH~bdKc@ETd6wp5ud(dWJbaGj8JaU^Sw2Ja(bFvF zX_im1JWcb^t1Q1l^O2WXeu?J6DVAND2OO4dnh#qnn=~IXSk`Io*H~6*?o(Kvq&b~q zd4lHNlPr(ZeDDOzV=edQ8s3{fg$FEF83`mNuz!eN|6e5UcYOU%Toi7I1dza%1nAXR z%CdZ%{cO%um9fX5_V?wsa$? z$%T1eE?l0QlNT0eFXk7o$`@v?o|H3d!Sc;;V=Y*)R11SfSSkjMj11+6jq*yku`%d3 zSLxC%^s)Rid(xLDMWI|Nh40kgT87TyVsNujWq%jzOE;E3%yg)vazK}}dFU1q^N2162 zkA9F!r_ibF&G&?Ur%rYAWrf#r1C16pq@%tVgw2 ztrY1_70V^|_nvrvXA5U%uE-hwni+Y%AZOV6ltsLKW^DcSD-lJJQDiHy)V-PF#+Hvv zv00Q%?^LdbH2~8nH2}p>jzrMH9MdwJi0Fcueqp;$FC{2 ztREq43Y21O1Qg%+UMf8}D8Basqu5-h`CHn|vbi|XLD?*`1t;7u-Kf@DkI}ePmI9xWVom0<%3@T z_X!uE{ZA@nMEX+tm2_Sb#oJ<492LG2J^-oHhi9e)@xV|%e;8hj%1fbqZMk}V^D7VS zlTdT2X}Gq!wc;7E(V=!ms%2Ux*N7>e-k}lnslb~dJfleQwAiS>O^p;ob9C;mMT)0( zYNWaF(#@?AQ#>U$>U(I7l$`6BhRN*!iWG0MQzKhZ75l*&K@m*xa8}+uSkz=|l-zZYN@lK6&!_c_9<}k%O5gQ$BQzP3o zG>iLRixh9HQzM(6Aw1YNQ{t2R2>d<(@g0Z}h(3r(h<=C+gbJZRPC|@BoPeO6 zB%=_=Aci4i2>N+J>UkLA5JVc{AjFFh--YOf7=SnqLCYP4$U@N18`81EbXf|54o}1f z5k4wqtw^IELtBE=s};;Pw}>u|0)YA#az zfkdu~;qop(;K~&La1vJ)S|WS`k>Vdp;;LAdp>eJ#YA#az{zR^dWAl#zg(-gDqq{=O z#IOvV)2?eOemaS(<7gJYB@`)sZz5OKa%|4=s^lD|_y?1?+NNz;oZ}Tn1~KIkPjFlv z2_OL^fCP{L5gjdN|M5H8zg`PkN^@u0!RP}AOR$R1fEU;k8}R7)A2pY(Kh!arUl7}+^$Bd&YhA9jF{q0cW7j|s%>*8$A}c~)!1mL zO^pmgF;$pL>i$Wx)Lf)^uXJjp+LpnY00NAd;=LRj9cfb|IvbhEtx=?SFLi2USqe;) z!PzyPDc)3UG}x|2nx-p!Bc^z6hen#~TCU5hQKWcIY&6iOMw;muFwq-l*CNHUJ2ldw zWbP@VF~zfDqqcMH*{;f;uSR9c)A_1}wMGI+00|%gB!C2v01`j~NB{{S0VIF~kN^@u z0!RP}AOR$R1Rh4G&hOBE>(R#MN;%%i)gFiWGk|ktL?V&$A2H#)IRF3v From f8f79355358a1d61b24f4c1350a923b36733a143 Mon Sep 17 00:00:00 2001 From: Benjamin Fleischer Date: Fri, 13 Oct 2017 22:00:43 -0500 Subject: [PATCH 05/13] Assert no regressions in gem-specific JSON document NOTE: the two gems are generating different JSON Essential difference - Including a user's posts's comments differ in that the included resource's relationship is `meta: {included: false}` instead of `data: { id: 20, type: :posts}` ```diff id: 39, type: comments attributes: { author: me, comment: wazzup } relationships: { post: { - data: { id: 20, type: posts } + meta: { included: false } } } } ``` Unimportant differences: - data: { type, id } vs. data: { id, type } Complete diff ```bash diff --side-by-side support/json_document-ams.json support/json_document-jsonapi_rb.json ``` ```diff { { "data": { "data": { "id": "1", "id": "1", "type": "users", "type": "users", "attributes": { "attributes": { "first_name": "Diana", "first_name": "Diana", "last_name": "Prince", "last_name": "Prince", "birthday": "2017-07-01 05:00:00 UTC", "birthday": "2017-07-01 05:00:00 UTC", "created_at": "2017-07-01 05:00:00 UTC", "created_at": "2017-07-01 05:00:00 UTC", "updated_at": "2017-07-01 05:00:00 UTC" "updated_at": "2017-07-01 05:00:00 UTC" }, }, "relationships": { "relationships": { "posts": { "posts": { "data": [ "data": [ { { "id": "1", | "type": "posts", "type": "posts" | "id": "1" }, }, { { "id": "2", | "type": "posts", "type": "posts" | "id": "2" }, }, { { "id": "3", | "type": "posts", "type": "posts" | "id": "3" }, }, { { "id": "4", | "type": "posts", "type": "posts" | "id": "4" }, }, { { "id": "5", | "type": "posts", "type": "posts" | "id": "5" }, }, { { "id": "6", | "type": "posts", "type": "posts" | "id": "6" }, }, { { "id": "7", | "type": "posts", "type": "posts" | "id": "7" }, }, { { "id": "8", | "type": "posts", "type": "posts" | "id": "8" }, }, { { "id": "9", | "type": "posts", "type": "posts" | "id": "9" }, }, { { "id": "10", | "type": "posts", "type": "posts" | "id": "10" }, }, { { "id": "11", | "type": "posts", "type": "posts" | "id": "11" }, }, { { "id": "12", | "type": "posts", "type": "posts" | "id": "12" }, }, { { "id": "13", | "type": "posts", "type": "posts" | "id": "13" }, }, { { "id": "14", | "type": "posts", "type": "posts" | "id": "14" }, }, { { "id": "15", | "type": "posts", "type": "posts" | "id": "15" }, }, { { "id": "16", | "type": "posts", "type": "posts" | "id": "16" }, }, { { "id": "17", | "type": "posts", "type": "posts" | "id": "17" }, }, { { "id": "18", | "type": "posts", "type": "posts" | "id": "18" }, }, { { "id": "19", | "type": "posts", "type": "posts" | "id": "19" }, }, { { "id": "20", | "type": "posts", "type": "posts" | "id": "20" } } ] ] } } } } }, }, "included": [ "included": [ { { "id": "1", "id": "1", "type": "posts", "type": "posts", "attributes": { "attributes": { "title": "Some Post", "title": "Some Post", "body": "awesome content", "body": "awesome content", "created_at": "2017-07-01 05:00:00 UTC", "created_at": "2017-07-01 05:00:00 UTC", "updated_at": "2017-07-01 05:00:00 UTC" "updated_at": "2017-07-01 05:00:00 UTC" }, }, "relationships": { "relationships": { "user": { "user": { "data": { | "meta": { "id": "1", | "included": false "type": "users" < } } }, }, "comments": { "comments": { "data": [ "data": [ { { "id": "1", | "type": "comments", "type": "comments" | "id": "1" }, }, { { "id": "2", | "type": "comments", "type": "comments" | "id": "2" } } ] ] } } } } }, }, { { "id": "1", | "id": "2", "type": "comments", | "type": "posts", "attributes": { "attributes": { "author": "me", | "title": "Some Post", "comment": "nice blog" | "body": "awesome content", > "created_at": "2017-07-01 05:00:00 UTC", > "updated_at": "2017-07-01 05:00:00 UTC" }, }, "relationships": { "relationships": { "post": { | "user": { "data": { | "meta": { "id": "1", | "included": false "type": "posts" < } } > }, > "comments": { > "data": [ > { > "type": "comments", > "id": "3" > }, > { > "type": "comments", > "id": "4" > } > ] } } } } }, }, { { "id": "2", | "id": "3", "type": "comments", | "type": "posts", "attributes": { "attributes": { "author": "me", | "title": "Some Post", "comment": "nice blog" | "body": "awesome content", > "created_at": "2017-07-01 05:00:00 UTC", > "updated_at": "2017-07-01 05:00:00 UTC" }, }, "relationships": { "relationships": { "post": { | "user": { "data": { | "meta": { "id": "1", | "included": false "type": "posts" < } } > }, > "comments": { > "data": [ > { > "type": "comments", > "id": "5" > }, > { > "type": "comments", > "id": "6" > } > ] } } } } }, }, { { "id": "2", | "id": "4", "type": "posts", "type": "posts", "attributes": { "attributes": { "title": "Some Post", "title": "Some Post", "body": "awesome content", "body": "awesome content", "created_at": "2017-07-01 05:00:00 UTC", "created_at": "2017-07-01 05:00:00 UTC", "updated_at": "2017-07-01 05:00:00 UTC" "updated_at": "2017-07-01 05:00:00 UTC" }, }, "relationships": { "relationships": { "user": { "user": { "data": { | "meta": { "id": "1", | "included": false "type": "users" < } } }, }, "comments": { "comments": { "data": [ "data": [ { { "id": "3", | "type": "comments", "type": "comments" | "id": "7" }, }, { { "id": "4", | "type": "comments", "type": "comments" | "id": "8" } } ] ] } } } } }, }, { { "id": "3", | "id": "5", "type": "comments", | "type": "posts", "attributes": { "attributes": { "author": "me", | "title": "Some Post", "comment": "nice blog" | "body": "awesome content", > "created_at": "2017-07-01 05:00:00 UTC", > "updated_at": "2017-07-01 05:00:00 UTC" }, }, "relationships": { "relationships": { "post": { | "user": { "data": { | "meta": { "id": "2", | "included": false "type": "posts" < } } > }, > "comments": { > "data": [ > { > "type": "comments", > "id": "9" > }, > { > "type": "comments", > "id": "10" > } > ] } } } } }, }, { { "id": "4", | "id": "6", "type": "comments", | "type": "posts", "attributes": { "attributes": { "author": "me", | "title": "Some Post", "comment": "nice blog" | "body": "awesome content", > "created_at": "2017-07-01 05:00:00 UTC", > "updated_at": "2017-07-01 05:00:00 UTC" }, }, "relationships": { "relationships": { "post": { | "user": { "data": { | "meta": { "id": "2", | "included": false "type": "posts" < } } > }, > "comments": { > "data": [ > { > "type": "comments", > "id": "11" > }, > { > "type": "comments", > "id": "12" > } > ] } } } } }, }, { { "id": "3", | "id": "7", "type": "posts", "type": "posts", "attributes": { "attributes": { "title": "Some Post", "title": "Some Post", "body": "awesome content", "body": "awesome content", "created_at": "2017-07-01 05:00:00 UTC", "created_at": "2017-07-01 05:00:00 UTC", "updated_at": "2017-07-01 05:00:00 UTC" "updated_at": "2017-07-01 05:00:00 UTC" }, }, "relationships": { "relationships": { "user": { "user": { "data": { | "meta": { "id": "1", | "included": false "type": "users" < } } }, }, "comments": { "comments": { "data": [ "data": [ { { "id": "5", | "type": "comments", "type": "comments" | "id": "13" }, }, { { "id": "6", | "type": "comments", "type": "comments" | "id": "14" } } ] ] } } } } }, }, { { "id": "5", | "id": "8", "type": "comments", | "type": "posts", "attributes": { "attributes": { "author": "me", | "title": "Some Post", "comment": "nice blog" | "body": "awesome content", > "created_at": "2017-07-01 05:00:00 UTC", > "updated_at": "2017-07-01 05:00:00 UTC" }, }, "relationships": { "relationships": { "post": { | "user": { "data": { | "meta": { "id": "3", | "included": false "type": "posts" < } } > }, > "comments": { > "data": [ > { > "type": "comments", > "id": "15" > }, > { > "type": "comments", > "id": "16" > } > ] } } } } }, }, { { "id": "6", | "id": "9", "type": "comments", | "type": "posts", "attributes": { "attributes": { "author": "me", | "title": "Some Post", "comment": "nice blog" | "body": "awesome content", > "created_at": "2017-07-01 05:00:00 UTC", > "updated_at": "2017-07-01 05:00:00 UTC" }, }, "relationships": { "relationships": { "post": { | "user": { "data": { | "meta": { "id": "3", | "included": false "type": "posts" < } } > }, > "comments": { > "data": [ > { > "type": "comments", > "id": "17" > }, > { > "type": "comments", > "id": "18" > } > ] } } } } }, }, { { "id": "4", | "id": "10", "type": "posts", "type": "posts", "attributes": { "attributes": { "title": "Some Post", "title": "Some Post", "body": "awesome content", "body": "awesome content", "created_at": "2017-07-01 05:00:00 UTC", "created_at": "2017-07-01 05:00:00 UTC", "updated_at": "2017-07-01 05:00:00 UTC" "updated_at": "2017-07-01 05:00:00 UTC" }, }, "relationships": { "relationships": { "user": { "user": { "data": { | "meta": { "id": "1", | "included": false "type": "users" < } } }, }, "comments": { "comments": { "data": [ "data": [ { { "id": "7", | "type": "comments", "type": "comments" | "id": "19" }, }, { { "id": "8", | "type": "comments", "type": "comments" | "id": "20" } } ] ] } } } } }, }, { { "id": "7", | "id": "11", "type": "comments", | "type": "posts", "attributes": { "attributes": { "author": "me", | "title": "Some Post", "comment": "nice blog" | "body": "awesome content", > "created_at": "2017-07-01 05:00:00 UTC", > "updated_at": "2017-07-01 05:00:00 UTC" }, }, "relationships": { "relationships": { "post": { | "user": { "data": { | "meta": { "id": "4", | "included": false "type": "posts" < } } > }, > "comments": { > "data": [ > { > "type": "comments", > "id": "21" > }, > { > "type": "comments", > "id": "22" > } > ] } } } } }, }, { { "id": "8", | "id": "12", "type": "comments", | "type": "posts", "attributes": { "attributes": { "author": "me", | "title": "Some Post", "comment": "nice blog" | "body": "awesome content", > "created_at": "2017-07-01 05:00:00 UTC", > "updated_at": "2017-07-01 05:00:00 UTC" }, }, "relationships": { "relationships": { "post": { | "user": { "data": { | "meta": { "id": "4", | "included": false "type": "posts" < } } > }, > "comments": { > "data": [ > { > "type": "comments", > "id": "23" > }, > { > "type": "comments", > "id": "24" > } > ] } } } } }, }, { { "id": "5", | "id": "13", "type": "posts", "type": "posts", "attributes": { "attributes": { "title": "Some Post", "title": "Some Post", "body": "awesome content", "body": "awesome content", "created_at": "2017-07-01 05:00:00 UTC", "created_at": "2017-07-01 05:00:00 UTC", "updated_at": "2017-07-01 05:00:00 UTC" "updated_at": "2017-07-01 05:00:00 UTC" }, }, "relationships": { "relationships": { "user": { "user": { "data": { | "meta": { "id": "1", | "included": false "type": "users" < } } }, }, "comments": { "comments": { "data": [ "data": [ { { "id": "9", | "type": "comments", "type": "comments" | "id": "25" }, }, { { "id": "10", | "type": "comments", "type": "comments" | "id": "26" } } ] ] } } } } }, }, { { "id": "9", | "id": "14", "type": "comments", | "type": "posts", "attributes": { "attributes": { "author": "me", | "title": "Some Post", "comment": "nice blog" | "body": "awesome content", > "created_at": "2017-07-01 05:00:00 UTC", > "updated_at": "2017-07-01 05:00:00 UTC" }, }, "relationships": { "relationships": { "post": { | "user": { "data": { | "meta": { "id": "5", | "included": false "type": "posts" < } } > }, > "comments": { > "data": [ > { > "type": "comments", > "id": "27" > }, > { > "type": "comments", > "id": "28" > } > ] } } } } }, }, { { "id": "10", | "id": "15", "type": "comments", | "type": "posts", "attributes": { "attributes": { "author": "me", | "title": "Some Post", "comment": "nice blog" | "body": "awesome content", > "created_at": "2017-07-01 05:00:00 UTC", > "updated_at": "2017-07-01 05:00:00 UTC" }, }, "relationships": { "relationships": { "post": { | "user": { "data": { | "meta": { "id": "5", | "included": false "type": "posts" < } } > }, > "comments": { > "data": [ > { > "type": "comments", > "id": "29" > }, > { > "type": "comments", > "id": "30" > } > ] } } } } }, }, { { "id": "6", | "id": "16", "type": "posts", "type": "posts", "attributes": { "attributes": { "title": "Some Post", "title": "Some Post", "body": "awesome content", "body": "awesome content", "created_at": "2017-07-01 05:00:00 UTC", "created_at": "2017-07-01 05:00:00 UTC", "updated_at": "2017-07-01 05:00:00 UTC" "updated_at": "2017-07-01 05:00:00 UTC" }, }, "relationships": { "relationships": { "user": { "user": { "data": { | "meta": { "id": "1", | "included": false "type": "users" < } } }, }, "comments": { "comments": { "data": [ "data": [ { { "id": "11", | "type": "comments", "type": "comments" | "id": "31" }, }, { { "id": "12", | "type": "comments", "type": "comments" | "id": "32" } } ] ] } } } } }, }, { { "id": "11", | "id": "17", "type": "comments", | "type": "posts", "attributes": { "attributes": { "author": "me", | "title": "Some Post", "comment": "nice blog" | "body": "awesome content", > "created_at": "2017-07-01 05:00:00 UTC", > "updated_at": "2017-07-01 05:00:00 UTC" }, }, "relationships": { "relationships": { "post": { | "user": { "data": { | "meta": { "id": "6", | "included": false "type": "posts" < } } > }, > "comments": { > "data": [ > { > "type": "comments", > "id": "33" > }, > { > "type": "comments", > "id": "34" > } > ] } } } } }, }, { { "id": "12", | "id": "18", "type": "comments", | "type": "posts", "attributes": { "attributes": { "author": "me", | "title": "Some Post", "comment": "nice blog" | "body": "awesome content", > "created_at": "2017-07-01 05:00:00 UTC", > "updated_at": "2017-07-01 05:00:00 UTC" }, }, "relationships": { "relationships": { "post": { | "user": { "data": { | "meta": { "id": "6", | "included": false "type": "posts" < } } > }, > "comments": { > "data": [ > { > "type": "comments", > "id": "35" > }, > { > "type": "comments", > "id": "36" > } > ] } } } } }, }, { { "id": "7", | "id": "19", "type": "posts", "type": "posts", "attributes": { "attributes": { "title": "Some Post", "title": "Some Post", "body": "awesome content", "body": "awesome content", "created_at": "2017-07-01 05:00:00 UTC", "created_at": "2017-07-01 05:00:00 UTC", "updated_at": "2017-07-01 05:00:00 UTC" "updated_at": "2017-07-01 05:00:00 UTC" }, }, "relationships": { "relationships": { "user": { "user": { "data": { | "meta": { "id": "1", | "included": false "type": "users" < } } }, }, "comments": { "comments": { "data": [ "data": [ { { "id": "13", | "type": "comments", "type": "comments" | "id": "37" }, }, { { "id": "14", | "type": "comments", "type": "comments" | "id": "38" } } ] ] } } } } }, }, { { "id": "13", | "id": "20", "type": "comments", | "type": "posts", "attributes": { "attributes": { "author": "me", | "title": "Some Post", "comment": "nice blog" | "body": "awesome content", > "created_at": "2017-07-01 05:00:00 UTC", > "updated_at": "2017-07-01 05:00:00 UTC" }, }, "relationships": { "relationships": { "post": { | "user": { "data": { | "meta": { "id": "7", | "included": false "type": "posts" < } } > }, > "comments": { > "data": [ > { > "type": "comments", > "id": "39" > }, > { > "type": "comments", > "id": "40" > } > ] } } } } }, }, { { "id": "14", | "id": "1", "type": "comments", "type": "comments", "attributes": { "attributes": { "author": "me", "author": "me", "comment": "nice blog" "comment": "nice blog" }, }, "relationships": { "relationships": { "post": { "post": { "data": { | "meta": { "id": "7", | "included": false "type": "posts" < } } } } } } }, }, { { "id": "8", | "id": "2", "type": "posts", | "type": "comments", "attributes": { "attributes": { "title": "Some Post", | "author": "me", "body": "awesome content", | "comment": "nice blog" "created_at": "2017-07-01 05:00:00 UTC", < "updated_at": "2017-07-01 05:00:00 UTC" < }, }, "relationships": { "relationships": { "user": { | "post": { "data": { | "meta": { "id": "1", | "included": false "type": "users" < } } }, < "comments": { < "data": [ < { < "id": "15", < "type": "comments" < }, < { < "id": "16", < "type": "comments" < } < ] < } } } } }, }, { { "id": "15", | "id": "3", "type": "comments", "type": "comments", "attributes": { "attributes": { "author": "me", "author": "me", "comment": "nice blog" "comment": "nice blog" }, }, "relationships": { "relationships": { "post": { "post": { "data": { | "meta": { "id": "8", | "included": false "type": "posts" < } } } } } } }, }, { { "id": "16", | "id": "4", "type": "comments", "type": "comments", "attributes": { "attributes": { "author": "me", "author": "me", "comment": "nice blog" "comment": "nice blog" }, }, "relationships": { "relationships": { "post": { "post": { "data": { | "meta": { "id": "8", | "included": false "type": "posts" < } } } } } } }, }, { { "id": "9", | "id": "5", "type": "posts", | "type": "comments", "attributes": { "attributes": { "title": "Some Post", | "author": "me", "body": "awesome content", | "comment": "nice blog" "created_at": "2017-07-01 05:00:00 UTC", < "updated_at": "2017-07-01 05:00:00 UTC" < }, }, "relationships": { "relationships": { "user": { | "post": { "data": { | "meta": { "id": "1", | "included": false "type": "users" < } } }, < "comments": { < "data": [ < { < "id": "17", < "type": "comments" < }, < { < "id": "18", < "type": "comments" < } < ] < } } } } }, }, { { "id": "17", | "id": "6", "type": "comments", "type": "comments", "attributes": { "attributes": { "author": "me", "author": "me", "comment": "nice blog" "comment": "nice blog" }, }, "relationships": { "relationships": { "post": { "post": { "data": { | "meta": { "id": "9", | "included": false "type": "posts" < } } } } } } }, }, { { "id": "18", | "id": "7", "type": "comments", "type": "comments", "attributes": { "attributes": { "author": "me", "author": "me", "comment": "nice blog" "comment": "nice blog" }, }, "relationships": { "relationships": { "post": { "post": { "data": { | "meta": { "id": "9", | "included": false "type": "posts" < } } } } } } }, }, { { "id": "10", | "id": "8", "type": "posts", | "type": "comments", "attributes": { "attributes": { "title": "Some Post", | "author": "me", "body": "awesome content", | "comment": "nice blog" "created_at": "2017-07-01 05:00:00 UTC", < "updated_at": "2017-07-01 05:00:00 UTC" < }, }, "relationships": { "relationships": { "user": { | "post": { "data": { | "meta": { "id": "1", | "included": false "type": "users" < } } }, < "comments": { < "data": [ < { < "id": "19", < "type": "comments" < }, < { < "id": "20", < "type": "comments" < } < ] < } } } } }, }, { { "id": "19", | "id": "9", "type": "comments", "type": "comments", "attributes": { "attributes": { "author": "me", "author": "me", "comment": "nice blog" "comment": "nice blog" }, }, "relationships": { "relationships": { "post": { "post": { "data": { | "meta": { "id": "10", | "included": false "type": "posts" < } } } } } } }, }, { { "id": "20", | "id": "10", "type": "comments", "type": "comments", "attributes": { "attributes": { "author": "me", "author": "me", "comment": "nice blog" "comment": "nice blog" }, }, "relationships": { "relationships": { "post": { "post": { "data": { | "meta": { "id": "10", | "included": false "type": "posts" < } } } } } } }, }, { { "id": "11", "id": "11", "type": "posts", | "type": "comments", "attributes": { "attributes": { "title": "Some Post", | "author": "me", "body": "awesome content", | "comment": "nice blog" "created_at": "2017-07-01 05:00:00 UTC", < "updated_at": "2017-07-01 05:00:00 UTC" < }, }, "relationships": { "relationships": { "user": { | "post": { "data": { | "meta": { "id": "1", | "included": false "type": "users" < } } }, < "comments": { < "data": [ < { < "id": "21", < "type": "comments" < }, < { < "id": "22", < "type": "comments" < } < ] < } } } } }, }, { { "id": "21", | "id": "12", "type": "comments", "type": "comments", "attributes": { "attributes": { "author": "me", "author": "me", "comment": "nice blog" "comment": "nice blog" }, }, "relationships": { "relationships": { "post": { "post": { "data": { | "meta": { "id": "11", | "included": false "type": "posts" < } } } } } } }, }, { { "id": "22", | "id": "13", "type": "comments", "type": "comments", "attributes": { "attributes": { "author": "me", "author": "me", "comment": "nice blog" "comment": "nice blog" }, }, "relationships": { "relationships": { "post": { "post": { "data": { | "meta": { "id": "11", | "included": false "type": "posts" < } } } } } } }, }, { { "id": "12", | "id": "14", "type": "posts", | "type": "comments", "attributes": { "attributes": { "title": "Some Post", | "author": "me", "body": "awesome content", | "comment": "nice blog" "created_at": "2017-07-01 05:00:00 UTC", < "updated_at": "2017-07-01 05:00:00 UTC" < }, }, "relationships": { "relationships": { "user": { | "post": { "data": { | "meta": { "id": "1", | "included": false "type": "users" < } } }, < "comments": { < "data": [ < { < "id": "23", < "type": "comments" < }, < { < "id": "24", < "type": "comments" < } < ] < } } } } }, }, { { "id": "23", | "id": "15", "type": "comments", "type": "comments", "attributes": { "attributes": { "author": "me", "author": "me", "comment": "nice blog" "comment": "nice blog" }, }, "relationships": { "relationships": { "post": { "post": { "data": { | "meta": { "id": "12", | "included": false "type": "posts" < } } } } } } }, }, { { "id": "24", | "id": "16", "type": "comments", "type": "comments", "attributes": { "attributes": { "author": "me", "author": "me", "comment": "nice blog" "comment": "nice blog" }, }, "relationships": { "relationships": { "post": { "post": { "data": { | "meta": { "id": "12", | "included": false "type": "posts" < } } } } } } }, }, { { "id": "13", | "id": "17", "type": "posts", | "type": "comments", "attributes": { "attributes": { "title": "Some Post", | "author": "me", "body": "awesome content", | "comment": "nice blog" "created_at": "2017-07-01 05:00:00 UTC", < "updated_at": "2017-07-01 05:00:00 UTC" < }, }, "relationships": { "relationships": { "user": { | "post": { "data": { | "meta": { "id": "1", | "included": false "type": "users" < } } }, < "comments": { < "data": [ < { < "id": "25", < "type": "comments" < }, < { < "id": "26", < "type": "comments" < } < ] < } } } } }, }, { { "id": "25", | "id": "18", "type": "comments", "type": "comments", "attributes": { "attributes": { "author": "me", "author": "me", "comment": "nice blog" "comment": "nice blog" }, }, "relationships": { "relationships": { "post": { "post": { "data": { | "meta": { "id": "13", | "included": false "type": "posts" < } } } } } } }, }, { { "id": "26", | "id": "19", "type": "comments", "type": "comments", "attributes": { "attributes": { "author": "me", "author": "me", "comment": "nice blog" "comment": "nice blog" }, }, "relationships": { "relationships": { "post": { "post": { "data": { | "meta": { "id": "13", | "included": false "type": "posts" < } } } } } } }, }, { { "id": "14", | "id": "20", "type": "posts", | "type": "comments", "attributes": { "attributes": { "title": "Some Post", | "author": "me", "body": "awesome content", | "comment": "nice blog" "created_at": "2017-07-01 05:00:00 UTC", < "updated_at": "2017-07-01 05:00:00 UTC" < }, }, "relationships": { "relationships": { "user": { | "post": { "data": { | "meta": { "id": "1", | "included": false "type": "users" < } } }, < "comments": { < "data": [ < { < "id": "27", < "type": "comments" < }, < { < "id": "28", < "type": "comments" < } < ] < } } } } }, }, { { "id": "27", | "id": "21", "type": "comments", "type": "comments", "attributes": { "attributes": { "author": "me", "author": "me", "comment": "nice blog" "comment": "nice blog" }, }, "relationships": { "relationships": { "post": { "post": { "data": { | "meta": { "id": "14", | "included": false "type": "posts" < } } } } } } }, }, { { "id": "28", | "id": "22", "type": "comments", "type": "comments", "attributes": { "attributes": { "author": "me", "author": "me", "comment": "nice blog" "comment": "nice blog" }, }, "relationships": { "relationships": { "post": { "post": { "data": { | "meta": { "id": "14", | "included": false "type": "posts" < } } } } } } }, }, { { "id": "15", | "id": "23", "type": "posts", | "type": "comments", "attributes": { "attributes": { "title": "Some Post", | "author": "me", "body": "awesome content", | "comment": "nice blog" "created_at": "2017-07-01 05:00:00 UTC", < "updated_at": "2017-07-01 05:00:00 UTC" < }, }, "relationships": { "relationships": { "user": { | "post": { "data": { | "meta": { "id": "1", | "included": false "type": "users" < } } }, < "comments": { < "data": [ < { < "id": "29", < "type": "comments" < }, < { < "id": "30", < "type": "comments" < } < ] < } } } } }, }, { { "id": "29", | "id": "24", "type": "comments", "type": "comments", "attributes": { "attributes": { "author": "me", "author": "me", "comment": "nice blog" "comment": "nice blog" }, }, "relationships": { "relationships": { "post": { "post": { "data": { | "meta": { "id": "15", | "included": false "type": "posts" < } } } } } } }, }, { { "id": "30", | "id": "25", "type": "comments", "type": "comments", "attributes": { "attributes": { "author": "me", "author": "me", "comment": "nice blog" "comment": "nice blog" }, }, "relationships": { "relationships": { "post": { "post": { "data": { | "meta": { "id": "15", | "included": false "type": "posts" < } } } } } } }, }, { { "id": "16", | "id": "26", "type": "posts", | "type": "comments", "attributes": { "attributes": { "title": "Some Post", | "author": "me", "body": "awesome content", | "comment": "nice blog" "created_at": "2017-07-01 05:00:00 UTC", < "updated_at": "2017-07-01 05:00:00 UTC" < }, }, "relationships": { "relationships": { "user": { | "post": { "data": { | "meta": { "id": "1", | "included": false "type": "users" < } } }, < "comments": { < "data": [ < { < "id": "31", < "type": "comments" < }, < { < "id": "32", < "type": "comments" < } < ] < } } } } }, }, { { "id": "31", | "id": "27", "type": "comments", "type": "comments", "attributes": { "attributes": { "author": "me", "author": "me", "comment": "nice blog" "comment": "nice blog" }, }, "relationships": { "relationships": { "post": { "post": { "data": { | "meta": { "id": "16", | "included": false "type": "posts" < } } } } } } }, }, { { "id": "32", | "id": "28", "type": "comments", "type": "comments", "attributes": { "attributes": { "author": "me", "author": "me", "comment": "nice blog" "comment": "nice blog" }, }, "relationships": { "relationships": { "post": { "post": { "data": { | "meta": { "id": "16", | "included": false "type": "posts" < } } } } } } }, }, { { "id": "17", | "id": "29", "type": "posts", | "type": "comments", "attributes": { "attributes": { "title": "Some Post", | "author": "me", "body": "awesome content", | "comment": "nice blog" "created_at": "2017-07-01 05:00:00 UTC", < "updated_at": "2017-07-01 05:00:00 UTC" < }, }, "relationships": { "relationships": { "user": { | "post": { "data": { | "meta": { "id": "1", | "included": false "type": "users" < } } }, < "comments": { < "data": [ < { < "id": "33", < "type": "comments" < }, < { < "id": "34", < "type": "comments" < } < ] < } } } } }, }, { { "id": "33", | "id": "30", "type": "comments", "type": "comments", "attributes": { "attributes": { "author": "me", "author": "me", "comment": "nice blog" "comment": "nice blog" }, }, "relationships": { "relationships": { "post": { "post": { "data": { | "meta": { "id": "17", | "included": false "type": "posts" < } } } } } } }, }, { { "id": "34", | "id": "31", "type": "comments", "type": "comments", "attributes": { "attributes": { "author": "me", "author": "me", "comment": "nice blog" "comment": "nice blog" }, }, "relationships": { "relationships": { "post": { "post": { "data": { | "meta": { "id": "17", | "included": false "type": "posts" < } } } } } } }, }, { { "id": "18", | "id": "32", "type": "posts", | "type": "comments", "attributes": { "attributes": { "title": "Some Post", | "author": "me", "body": "awesome content", | "comment": "nice blog" "created_at": "2017-07-01 05:00:00 UTC", < "updated_at": "2017-07-01 05:00:00 UTC" < }, }, "relationships": { "relationships": { "user": { | "post": { "data": { | "meta": { "id": "1", | "included": false "type": "users" < } } }, < "comments": { < "data": [ < { < "id": "35", < "type": "comments" < }, < { < "id": "36", < "type": "comments" < } < ] < } } } } }, }, { { "id": "35", | "id": "33", "type": "comments", "type": "comments", "attributes": { "attributes": { "author": "me", "author": "me", "comment": "nice blog" "comment": "nice blog" }, }, "relationships": { "relationships": { "post": { "post": { "data": { | "meta": { "id": "18", | "included": false "type": "posts" < } } } } } } }, }, { { "id": "36", | "id": "34", "type": "comments", "type": "comments", "attributes": { "attributes": { "author": "me", "author": "me", "comment": "nice blog" "comment": "nice blog" }, }, "relationships": { "relationships": { "post": { "post": { "data": { | "meta": { "id": "18", | "included": false "type": "posts" < } } } } } } }, }, { { "id": "19", | "id": "35", "type": "posts", | "type": "comments", "attributes": { "attributes": { "title": "Some Post", | "author": "me", "body": "awesome content", | "comment": "nice blog" "created_at": "2017-07-01 05:00:00 UTC", < "updated_at": "2017-07-01 05:00:00 UTC" < }, }, "relationships": { "relationships": { "user": { | "post": { "data": { | "meta": { "id": "1", | "included": false "type": "users" < } } }, < "comments": { < "data": [ < { < "id": "37", < "type": "comments" < }, < { < "id": "38", < "type": "comments" < } < ] < } } } } }, }, { { "id": "37", | "id": "36", "type": "comments", "type": "comments", "attributes": { "attributes": { "author": "me", "author": "me", "comment": "nice blog" "comment": "nice blog" }, }, "relationships": { "relationships": { "post": { "post": { "data": { | "meta": { "id": "19", | "included": false "type": "posts" < } } } } } } }, }, { { "id": "38", | "id": "37", "type": "comments", "type": "comments", "attributes": { "attributes": { "author": "me", "author": "me", "comment": "nice blog" "comment": "nice blog" }, }, "relationships": { "relationships": { "post": { "post": { "data": { | "meta": { "id": "19", | "included": false "type": "posts" < } } } } } } }, }, { { "id": "20", | "id": "38", "type": "posts", | "type": "comments", "attributes": { "attributes": { "title": "Some Post", | "author": "me", "body": "awesome content", | "comment": "nice blog" "created_at": "2017-07-01 05:00:00 UTC", < "updated_at": "2017-07-01 05:00:00 UTC" < }, }, "relationships": { "relationships": { "user": { | "post": { "data": { | "meta": { "id": "1", | "included": false "type": "users" < } } }, < "comments": { < "data": [ < { < "id": "39", < "type": "comments" < }, < { < "id": "40", < "type": "comments" < } < ] < } } } } }, }, { { "id": "39", "id": "39", "type": "comments", "type": "comments", "attributes": { "attributes": { "author": "me", "author": "me", "comment": "nice blog" "comment": "nice blog" }, }, "relationships": { "relationships": { "post": { "post": { "data": { | "meta": { "id": "20", | "included": false "type": "posts" < } } } } } } }, }, { { "id": "40", "id": "40", "type": "comments", "type": "comments", "attributes": { "attributes": { "author": "me", "author": "me", "comment": "nice blog" "comment": "nice blog" }, }, "relationships": { "relationships": { "post": { "post": { "data": { | "meta": { "id": "20", | "included": false "type": "posts" < } } } } } } } } ] ] } } ``` --- .../serialization_libraries/benchmark.rb | 2 + .../support/bench_helper.rb | 33 + .../support/json_document-ams.json | 1341 +++++++++++++++++ .../support/json_document-jsonapi_rb.json | 1281 ++++++++++++++++ 4 files changed, 2657 insertions(+) create mode 100644 benchmarks/serialization_libraries/support/json_document-ams.json create mode 100644 benchmarks/serialization_libraries/support/json_document-jsonapi_rb.json diff --git a/benchmarks/serialization_libraries/benchmark.rb b/benchmarks/serialization_libraries/benchmark.rb index 93dbef17..6793a17a 100644 --- a/benchmarks/serialization_libraries/benchmark.rb +++ b/benchmarks/serialization_libraries/benchmark.rb @@ -24,6 +24,8 @@ GC.disable %i[ips memory].each do |bench| BenchHelper.clear_data BenchHelper.seed_data + BenchHelper.validate_render(:ams) + BenchHelper.validate_render(:jsonapi_rb) Benchmark.send(bench) do |x| x.config(time: 10, warmup: 5, stats: :bootstrap, confidence: 95) if x.respond_to?(:config) diff --git a/benchmarks/serialization_libraries/support/bench_helper.rb b/benchmarks/serialization_libraries/support/bench_helper.rb index a512303b..bedebd3f 100644 --- a/benchmarks/serialization_libraries/support/bench_helper.rb +++ b/benchmarks/serialization_libraries/support/bench_helper.rb @@ -24,6 +24,39 @@ module BenchHelper end end + def validate_render(render_gem) + expected_json_file = File.join("support", "json_document-#{render_gem}.json") + json_document = test_render(render_gem) + assert_equal_json("[#{render_gem}] :test_render", expected_json_file, json_document) + json_document = test_manual_eagerload(render_gem) + assert_equal_json("[#{render_gem}] :test_manual_eagerload", expected_json_file, json_document) + end + + require "fileutils" + def assert_equal_json(description, expected_json_file, actual_json_document) + # 1. in tmp/ + temp_dir = "tmp" + FileUtils.mkdir_p(temp_dir) + # 2. write pretty actual json doc + actual_json_file = File.join(temp_dir, "actual--#{File.basename(expected_json_file)}") + actual_json_document = JSON.pretty_generate(actual_json_document) + File.write(actual_json_file, actual_json_document) + # 3. if expected json doc missing, copy actual to expected + unless File.exist?(expected_json_file) + FileUtils.cp(actual_json_file, expected_json_file) + end + # 4. Check for differences + cmd = "diff --suppress-common-lines --side-by-side #{expected_json_file} #{actual_json_file}" + diff = `#{cmd}`.chomp + # 5. If none, 'true', they are equal + # else make a full diff for later review + return true if diff.empty? + cmd = "diff --side-by-side #{expected_json_file} #{actual_json_file} > #{File.join(temp_dir, "actual--#{File.basename(expected_json_file)}")}.diff" + system(cmd) + # 6. abort run, print brief diff + abort "#{description}. Invalid JSON document.\nDiff:\n#{diff}}" + end + def test_render(render_gem) render_data( User.first, diff --git a/benchmarks/serialization_libraries/support/json_document-ams.json b/benchmarks/serialization_libraries/support/json_document-ams.json new file mode 100644 index 00000000..7bcdbc84 --- /dev/null +++ b/benchmarks/serialization_libraries/support/json_document-ams.json @@ -0,0 +1,1341 @@ +{ + "data": { + "id": "1", + "type": "users", + "attributes": { + "first_name": "Diana", + "last_name": "Prince", + "birthday": "2017-07-01 05:00:00 UTC", + "created_at": "2017-07-01 05:00:00 UTC", + "updated_at": "2017-07-01 05:00:00 UTC" + }, + "relationships": { + "posts": { + "data": [ + { + "id": "1", + "type": "posts" + }, + { + "id": "2", + "type": "posts" + }, + { + "id": "3", + "type": "posts" + }, + { + "id": "4", + "type": "posts" + }, + { + "id": "5", + "type": "posts" + }, + { + "id": "6", + "type": "posts" + }, + { + "id": "7", + "type": "posts" + }, + { + "id": "8", + "type": "posts" + }, + { + "id": "9", + "type": "posts" + }, + { + "id": "10", + "type": "posts" + }, + { + "id": "11", + "type": "posts" + }, + { + "id": "12", + "type": "posts" + }, + { + "id": "13", + "type": "posts" + }, + { + "id": "14", + "type": "posts" + }, + { + "id": "15", + "type": "posts" + }, + { + "id": "16", + "type": "posts" + }, + { + "id": "17", + "type": "posts" + }, + { + "id": "18", + "type": "posts" + }, + { + "id": "19", + "type": "posts" + }, + { + "id": "20", + "type": "posts" + } + ] + } + } + }, + "included": [ + { + "id": "1", + "type": "posts", + "attributes": { + "title": "Some Post", + "body": "awesome content", + "created_at": "2017-07-01 05:00:00 UTC", + "updated_at": "2017-07-01 05:00:00 UTC" + }, + "relationships": { + "user": { + "data": { + "id": "1", + "type": "users" + } + }, + "comments": { + "data": [ + { + "id": "1", + "type": "comments" + }, + { + "id": "2", + "type": "comments" + } + ] + } + } + }, + { + "id": "1", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "data": { + "id": "1", + "type": "posts" + } + } + } + }, + { + "id": "2", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "data": { + "id": "1", + "type": "posts" + } + } + } + }, + { + "id": "2", + "type": "posts", + "attributes": { + "title": "Some Post", + "body": "awesome content", + "created_at": "2017-07-01 05:00:00 UTC", + "updated_at": "2017-07-01 05:00:00 UTC" + }, + "relationships": { + "user": { + "data": { + "id": "1", + "type": "users" + } + }, + "comments": { + "data": [ + { + "id": "3", + "type": "comments" + }, + { + "id": "4", + "type": "comments" + } + ] + } + } + }, + { + "id": "3", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "data": { + "id": "2", + "type": "posts" + } + } + } + }, + { + "id": "4", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "data": { + "id": "2", + "type": "posts" + } + } + } + }, + { + "id": "3", + "type": "posts", + "attributes": { + "title": "Some Post", + "body": "awesome content", + "created_at": "2017-07-01 05:00:00 UTC", + "updated_at": "2017-07-01 05:00:00 UTC" + }, + "relationships": { + "user": { + "data": { + "id": "1", + "type": "users" + } + }, + "comments": { + "data": [ + { + "id": "5", + "type": "comments" + }, + { + "id": "6", + "type": "comments" + } + ] + } + } + }, + { + "id": "5", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "data": { + "id": "3", + "type": "posts" + } + } + } + }, + { + "id": "6", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "data": { + "id": "3", + "type": "posts" + } + } + } + }, + { + "id": "4", + "type": "posts", + "attributes": { + "title": "Some Post", + "body": "awesome content", + "created_at": "2017-07-01 05:00:00 UTC", + "updated_at": "2017-07-01 05:00:00 UTC" + }, + "relationships": { + "user": { + "data": { + "id": "1", + "type": "users" + } + }, + "comments": { + "data": [ + { + "id": "7", + "type": "comments" + }, + { + "id": "8", + "type": "comments" + } + ] + } + } + }, + { + "id": "7", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "data": { + "id": "4", + "type": "posts" + } + } + } + }, + { + "id": "8", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "data": { + "id": "4", + "type": "posts" + } + } + } + }, + { + "id": "5", + "type": "posts", + "attributes": { + "title": "Some Post", + "body": "awesome content", + "created_at": "2017-07-01 05:00:00 UTC", + "updated_at": "2017-07-01 05:00:00 UTC" + }, + "relationships": { + "user": { + "data": { + "id": "1", + "type": "users" + } + }, + "comments": { + "data": [ + { + "id": "9", + "type": "comments" + }, + { + "id": "10", + "type": "comments" + } + ] + } + } + }, + { + "id": "9", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "data": { + "id": "5", + "type": "posts" + } + } + } + }, + { + "id": "10", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "data": { + "id": "5", + "type": "posts" + } + } + } + }, + { + "id": "6", + "type": "posts", + "attributes": { + "title": "Some Post", + "body": "awesome content", + "created_at": "2017-07-01 05:00:00 UTC", + "updated_at": "2017-07-01 05:00:00 UTC" + }, + "relationships": { + "user": { + "data": { + "id": "1", + "type": "users" + } + }, + "comments": { + "data": [ + { + "id": "11", + "type": "comments" + }, + { + "id": "12", + "type": "comments" + } + ] + } + } + }, + { + "id": "11", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "data": { + "id": "6", + "type": "posts" + } + } + } + }, + { + "id": "12", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "data": { + "id": "6", + "type": "posts" + } + } + } + }, + { + "id": "7", + "type": "posts", + "attributes": { + "title": "Some Post", + "body": "awesome content", + "created_at": "2017-07-01 05:00:00 UTC", + "updated_at": "2017-07-01 05:00:00 UTC" + }, + "relationships": { + "user": { + "data": { + "id": "1", + "type": "users" + } + }, + "comments": { + "data": [ + { + "id": "13", + "type": "comments" + }, + { + "id": "14", + "type": "comments" + } + ] + } + } + }, + { + "id": "13", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "data": { + "id": "7", + "type": "posts" + } + } + } + }, + { + "id": "14", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "data": { + "id": "7", + "type": "posts" + } + } + } + }, + { + "id": "8", + "type": "posts", + "attributes": { + "title": "Some Post", + "body": "awesome content", + "created_at": "2017-07-01 05:00:00 UTC", + "updated_at": "2017-07-01 05:00:00 UTC" + }, + "relationships": { + "user": { + "data": { + "id": "1", + "type": "users" + } + }, + "comments": { + "data": [ + { + "id": "15", + "type": "comments" + }, + { + "id": "16", + "type": "comments" + } + ] + } + } + }, + { + "id": "15", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "data": { + "id": "8", + "type": "posts" + } + } + } + }, + { + "id": "16", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "data": { + "id": "8", + "type": "posts" + } + } + } + }, + { + "id": "9", + "type": "posts", + "attributes": { + "title": "Some Post", + "body": "awesome content", + "created_at": "2017-07-01 05:00:00 UTC", + "updated_at": "2017-07-01 05:00:00 UTC" + }, + "relationships": { + "user": { + "data": { + "id": "1", + "type": "users" + } + }, + "comments": { + "data": [ + { + "id": "17", + "type": "comments" + }, + { + "id": "18", + "type": "comments" + } + ] + } + } + }, + { + "id": "17", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "data": { + "id": "9", + "type": "posts" + } + } + } + }, + { + "id": "18", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "data": { + "id": "9", + "type": "posts" + } + } + } + }, + { + "id": "10", + "type": "posts", + "attributes": { + "title": "Some Post", + "body": "awesome content", + "created_at": "2017-07-01 05:00:00 UTC", + "updated_at": "2017-07-01 05:00:00 UTC" + }, + "relationships": { + "user": { + "data": { + "id": "1", + "type": "users" + } + }, + "comments": { + "data": [ + { + "id": "19", + "type": "comments" + }, + { + "id": "20", + "type": "comments" + } + ] + } + } + }, + { + "id": "19", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "data": { + "id": "10", + "type": "posts" + } + } + } + }, + { + "id": "20", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "data": { + "id": "10", + "type": "posts" + } + } + } + }, + { + "id": "11", + "type": "posts", + "attributes": { + "title": "Some Post", + "body": "awesome content", + "created_at": "2017-07-01 05:00:00 UTC", + "updated_at": "2017-07-01 05:00:00 UTC" + }, + "relationships": { + "user": { + "data": { + "id": "1", + "type": "users" + } + }, + "comments": { + "data": [ + { + "id": "21", + "type": "comments" + }, + { + "id": "22", + "type": "comments" + } + ] + } + } + }, + { + "id": "21", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "data": { + "id": "11", + "type": "posts" + } + } + } + }, + { + "id": "22", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "data": { + "id": "11", + "type": "posts" + } + } + } + }, + { + "id": "12", + "type": "posts", + "attributes": { + "title": "Some Post", + "body": "awesome content", + "created_at": "2017-07-01 05:00:00 UTC", + "updated_at": "2017-07-01 05:00:00 UTC" + }, + "relationships": { + "user": { + "data": { + "id": "1", + "type": "users" + } + }, + "comments": { + "data": [ + { + "id": "23", + "type": "comments" + }, + { + "id": "24", + "type": "comments" + } + ] + } + } + }, + { + "id": "23", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "data": { + "id": "12", + "type": "posts" + } + } + } + }, + { + "id": "24", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "data": { + "id": "12", + "type": "posts" + } + } + } + }, + { + "id": "13", + "type": "posts", + "attributes": { + "title": "Some Post", + "body": "awesome content", + "created_at": "2017-07-01 05:00:00 UTC", + "updated_at": "2017-07-01 05:00:00 UTC" + }, + "relationships": { + "user": { + "data": { + "id": "1", + "type": "users" + } + }, + "comments": { + "data": [ + { + "id": "25", + "type": "comments" + }, + { + "id": "26", + "type": "comments" + } + ] + } + } + }, + { + "id": "25", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "data": { + "id": "13", + "type": "posts" + } + } + } + }, + { + "id": "26", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "data": { + "id": "13", + "type": "posts" + } + } + } + }, + { + "id": "14", + "type": "posts", + "attributes": { + "title": "Some Post", + "body": "awesome content", + "created_at": "2017-07-01 05:00:00 UTC", + "updated_at": "2017-07-01 05:00:00 UTC" + }, + "relationships": { + "user": { + "data": { + "id": "1", + "type": "users" + } + }, + "comments": { + "data": [ + { + "id": "27", + "type": "comments" + }, + { + "id": "28", + "type": "comments" + } + ] + } + } + }, + { + "id": "27", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "data": { + "id": "14", + "type": "posts" + } + } + } + }, + { + "id": "28", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "data": { + "id": "14", + "type": "posts" + } + } + } + }, + { + "id": "15", + "type": "posts", + "attributes": { + "title": "Some Post", + "body": "awesome content", + "created_at": "2017-07-01 05:00:00 UTC", + "updated_at": "2017-07-01 05:00:00 UTC" + }, + "relationships": { + "user": { + "data": { + "id": "1", + "type": "users" + } + }, + "comments": { + "data": [ + { + "id": "29", + "type": "comments" + }, + { + "id": "30", + "type": "comments" + } + ] + } + } + }, + { + "id": "29", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "data": { + "id": "15", + "type": "posts" + } + } + } + }, + { + "id": "30", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "data": { + "id": "15", + "type": "posts" + } + } + } + }, + { + "id": "16", + "type": "posts", + "attributes": { + "title": "Some Post", + "body": "awesome content", + "created_at": "2017-07-01 05:00:00 UTC", + "updated_at": "2017-07-01 05:00:00 UTC" + }, + "relationships": { + "user": { + "data": { + "id": "1", + "type": "users" + } + }, + "comments": { + "data": [ + { + "id": "31", + "type": "comments" + }, + { + "id": "32", + "type": "comments" + } + ] + } + } + }, + { + "id": "31", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "data": { + "id": "16", + "type": "posts" + } + } + } + }, + { + "id": "32", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "data": { + "id": "16", + "type": "posts" + } + } + } + }, + { + "id": "17", + "type": "posts", + "attributes": { + "title": "Some Post", + "body": "awesome content", + "created_at": "2017-07-01 05:00:00 UTC", + "updated_at": "2017-07-01 05:00:00 UTC" + }, + "relationships": { + "user": { + "data": { + "id": "1", + "type": "users" + } + }, + "comments": { + "data": [ + { + "id": "33", + "type": "comments" + }, + { + "id": "34", + "type": "comments" + } + ] + } + } + }, + { + "id": "33", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "data": { + "id": "17", + "type": "posts" + } + } + } + }, + { + "id": "34", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "data": { + "id": "17", + "type": "posts" + } + } + } + }, + { + "id": "18", + "type": "posts", + "attributes": { + "title": "Some Post", + "body": "awesome content", + "created_at": "2017-07-01 05:00:00 UTC", + "updated_at": "2017-07-01 05:00:00 UTC" + }, + "relationships": { + "user": { + "data": { + "id": "1", + "type": "users" + } + }, + "comments": { + "data": [ + { + "id": "35", + "type": "comments" + }, + { + "id": "36", + "type": "comments" + } + ] + } + } + }, + { + "id": "35", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "data": { + "id": "18", + "type": "posts" + } + } + } + }, + { + "id": "36", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "data": { + "id": "18", + "type": "posts" + } + } + } + }, + { + "id": "19", + "type": "posts", + "attributes": { + "title": "Some Post", + "body": "awesome content", + "created_at": "2017-07-01 05:00:00 UTC", + "updated_at": "2017-07-01 05:00:00 UTC" + }, + "relationships": { + "user": { + "data": { + "id": "1", + "type": "users" + } + }, + "comments": { + "data": [ + { + "id": "37", + "type": "comments" + }, + { + "id": "38", + "type": "comments" + } + ] + } + } + }, + { + "id": "37", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "data": { + "id": "19", + "type": "posts" + } + } + } + }, + { + "id": "38", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "data": { + "id": "19", + "type": "posts" + } + } + } + }, + { + "id": "20", + "type": "posts", + "attributes": { + "title": "Some Post", + "body": "awesome content", + "created_at": "2017-07-01 05:00:00 UTC", + "updated_at": "2017-07-01 05:00:00 UTC" + }, + "relationships": { + "user": { + "data": { + "id": "1", + "type": "users" + } + }, + "comments": { + "data": [ + { + "id": "39", + "type": "comments" + }, + { + "id": "40", + "type": "comments" + } + ] + } + } + }, + { + "id": "39", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "data": { + "id": "20", + "type": "posts" + } + } + } + }, + { + "id": "40", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "data": { + "id": "20", + "type": "posts" + } + } + } + } + ] +} \ No newline at end of file diff --git a/benchmarks/serialization_libraries/support/json_document-jsonapi_rb.json b/benchmarks/serialization_libraries/support/json_document-jsonapi_rb.json new file mode 100644 index 00000000..525a05a3 --- /dev/null +++ b/benchmarks/serialization_libraries/support/json_document-jsonapi_rb.json @@ -0,0 +1,1281 @@ +{ + "data": { + "id": "1", + "type": "users", + "attributes": { + "first_name": "Diana", + "last_name": "Prince", + "birthday": "2017-07-01 05:00:00 UTC", + "created_at": "2017-07-01 05:00:00 UTC", + "updated_at": "2017-07-01 05:00:00 UTC" + }, + "relationships": { + "posts": { + "data": [ + { + "type": "posts", + "id": "1" + }, + { + "type": "posts", + "id": "2" + }, + { + "type": "posts", + "id": "3" + }, + { + "type": "posts", + "id": "4" + }, + { + "type": "posts", + "id": "5" + }, + { + "type": "posts", + "id": "6" + }, + { + "type": "posts", + "id": "7" + }, + { + "type": "posts", + "id": "8" + }, + { + "type": "posts", + "id": "9" + }, + { + "type": "posts", + "id": "10" + }, + { + "type": "posts", + "id": "11" + }, + { + "type": "posts", + "id": "12" + }, + { + "type": "posts", + "id": "13" + }, + { + "type": "posts", + "id": "14" + }, + { + "type": "posts", + "id": "15" + }, + { + "type": "posts", + "id": "16" + }, + { + "type": "posts", + "id": "17" + }, + { + "type": "posts", + "id": "18" + }, + { + "type": "posts", + "id": "19" + }, + { + "type": "posts", + "id": "20" + } + ] + } + } + }, + "included": [ + { + "id": "1", + "type": "posts", + "attributes": { + "title": "Some Post", + "body": "awesome content", + "created_at": "2017-07-01 05:00:00 UTC", + "updated_at": "2017-07-01 05:00:00 UTC" + }, + "relationships": { + "user": { + "meta": { + "included": false + } + }, + "comments": { + "data": [ + { + "type": "comments", + "id": "1" + }, + { + "type": "comments", + "id": "2" + } + ] + } + } + }, + { + "id": "2", + "type": "posts", + "attributes": { + "title": "Some Post", + "body": "awesome content", + "created_at": "2017-07-01 05:00:00 UTC", + "updated_at": "2017-07-01 05:00:00 UTC" + }, + "relationships": { + "user": { + "meta": { + "included": false + } + }, + "comments": { + "data": [ + { + "type": "comments", + "id": "3" + }, + { + "type": "comments", + "id": "4" + } + ] + } + } + }, + { + "id": "3", + "type": "posts", + "attributes": { + "title": "Some Post", + "body": "awesome content", + "created_at": "2017-07-01 05:00:00 UTC", + "updated_at": "2017-07-01 05:00:00 UTC" + }, + "relationships": { + "user": { + "meta": { + "included": false + } + }, + "comments": { + "data": [ + { + "type": "comments", + "id": "5" + }, + { + "type": "comments", + "id": "6" + } + ] + } + } + }, + { + "id": "4", + "type": "posts", + "attributes": { + "title": "Some Post", + "body": "awesome content", + "created_at": "2017-07-01 05:00:00 UTC", + "updated_at": "2017-07-01 05:00:00 UTC" + }, + "relationships": { + "user": { + "meta": { + "included": false + } + }, + "comments": { + "data": [ + { + "type": "comments", + "id": "7" + }, + { + "type": "comments", + "id": "8" + } + ] + } + } + }, + { + "id": "5", + "type": "posts", + "attributes": { + "title": "Some Post", + "body": "awesome content", + "created_at": "2017-07-01 05:00:00 UTC", + "updated_at": "2017-07-01 05:00:00 UTC" + }, + "relationships": { + "user": { + "meta": { + "included": false + } + }, + "comments": { + "data": [ + { + "type": "comments", + "id": "9" + }, + { + "type": "comments", + "id": "10" + } + ] + } + } + }, + { + "id": "6", + "type": "posts", + "attributes": { + "title": "Some Post", + "body": "awesome content", + "created_at": "2017-07-01 05:00:00 UTC", + "updated_at": "2017-07-01 05:00:00 UTC" + }, + "relationships": { + "user": { + "meta": { + "included": false + } + }, + "comments": { + "data": [ + { + "type": "comments", + "id": "11" + }, + { + "type": "comments", + "id": "12" + } + ] + } + } + }, + { + "id": "7", + "type": "posts", + "attributes": { + "title": "Some Post", + "body": "awesome content", + "created_at": "2017-07-01 05:00:00 UTC", + "updated_at": "2017-07-01 05:00:00 UTC" + }, + "relationships": { + "user": { + "meta": { + "included": false + } + }, + "comments": { + "data": [ + { + "type": "comments", + "id": "13" + }, + { + "type": "comments", + "id": "14" + } + ] + } + } + }, + { + "id": "8", + "type": "posts", + "attributes": { + "title": "Some Post", + "body": "awesome content", + "created_at": "2017-07-01 05:00:00 UTC", + "updated_at": "2017-07-01 05:00:00 UTC" + }, + "relationships": { + "user": { + "meta": { + "included": false + } + }, + "comments": { + "data": [ + { + "type": "comments", + "id": "15" + }, + { + "type": "comments", + "id": "16" + } + ] + } + } + }, + { + "id": "9", + "type": "posts", + "attributes": { + "title": "Some Post", + "body": "awesome content", + "created_at": "2017-07-01 05:00:00 UTC", + "updated_at": "2017-07-01 05:00:00 UTC" + }, + "relationships": { + "user": { + "meta": { + "included": false + } + }, + "comments": { + "data": [ + { + "type": "comments", + "id": "17" + }, + { + "type": "comments", + "id": "18" + } + ] + } + } + }, + { + "id": "10", + "type": "posts", + "attributes": { + "title": "Some Post", + "body": "awesome content", + "created_at": "2017-07-01 05:00:00 UTC", + "updated_at": "2017-07-01 05:00:00 UTC" + }, + "relationships": { + "user": { + "meta": { + "included": false + } + }, + "comments": { + "data": [ + { + "type": "comments", + "id": "19" + }, + { + "type": "comments", + "id": "20" + } + ] + } + } + }, + { + "id": "11", + "type": "posts", + "attributes": { + "title": "Some Post", + "body": "awesome content", + "created_at": "2017-07-01 05:00:00 UTC", + "updated_at": "2017-07-01 05:00:00 UTC" + }, + "relationships": { + "user": { + "meta": { + "included": false + } + }, + "comments": { + "data": [ + { + "type": "comments", + "id": "21" + }, + { + "type": "comments", + "id": "22" + } + ] + } + } + }, + { + "id": "12", + "type": "posts", + "attributes": { + "title": "Some Post", + "body": "awesome content", + "created_at": "2017-07-01 05:00:00 UTC", + "updated_at": "2017-07-01 05:00:00 UTC" + }, + "relationships": { + "user": { + "meta": { + "included": false + } + }, + "comments": { + "data": [ + { + "type": "comments", + "id": "23" + }, + { + "type": "comments", + "id": "24" + } + ] + } + } + }, + { + "id": "13", + "type": "posts", + "attributes": { + "title": "Some Post", + "body": "awesome content", + "created_at": "2017-07-01 05:00:00 UTC", + "updated_at": "2017-07-01 05:00:00 UTC" + }, + "relationships": { + "user": { + "meta": { + "included": false + } + }, + "comments": { + "data": [ + { + "type": "comments", + "id": "25" + }, + { + "type": "comments", + "id": "26" + } + ] + } + } + }, + { + "id": "14", + "type": "posts", + "attributes": { + "title": "Some Post", + "body": "awesome content", + "created_at": "2017-07-01 05:00:00 UTC", + "updated_at": "2017-07-01 05:00:00 UTC" + }, + "relationships": { + "user": { + "meta": { + "included": false + } + }, + "comments": { + "data": [ + { + "type": "comments", + "id": "27" + }, + { + "type": "comments", + "id": "28" + } + ] + } + } + }, + { + "id": "15", + "type": "posts", + "attributes": { + "title": "Some Post", + "body": "awesome content", + "created_at": "2017-07-01 05:00:00 UTC", + "updated_at": "2017-07-01 05:00:00 UTC" + }, + "relationships": { + "user": { + "meta": { + "included": false + } + }, + "comments": { + "data": [ + { + "type": "comments", + "id": "29" + }, + { + "type": "comments", + "id": "30" + } + ] + } + } + }, + { + "id": "16", + "type": "posts", + "attributes": { + "title": "Some Post", + "body": "awesome content", + "created_at": "2017-07-01 05:00:00 UTC", + "updated_at": "2017-07-01 05:00:00 UTC" + }, + "relationships": { + "user": { + "meta": { + "included": false + } + }, + "comments": { + "data": [ + { + "type": "comments", + "id": "31" + }, + { + "type": "comments", + "id": "32" + } + ] + } + } + }, + { + "id": "17", + "type": "posts", + "attributes": { + "title": "Some Post", + "body": "awesome content", + "created_at": "2017-07-01 05:00:00 UTC", + "updated_at": "2017-07-01 05:00:00 UTC" + }, + "relationships": { + "user": { + "meta": { + "included": false + } + }, + "comments": { + "data": [ + { + "type": "comments", + "id": "33" + }, + { + "type": "comments", + "id": "34" + } + ] + } + } + }, + { + "id": "18", + "type": "posts", + "attributes": { + "title": "Some Post", + "body": "awesome content", + "created_at": "2017-07-01 05:00:00 UTC", + "updated_at": "2017-07-01 05:00:00 UTC" + }, + "relationships": { + "user": { + "meta": { + "included": false + } + }, + "comments": { + "data": [ + { + "type": "comments", + "id": "35" + }, + { + "type": "comments", + "id": "36" + } + ] + } + } + }, + { + "id": "19", + "type": "posts", + "attributes": { + "title": "Some Post", + "body": "awesome content", + "created_at": "2017-07-01 05:00:00 UTC", + "updated_at": "2017-07-01 05:00:00 UTC" + }, + "relationships": { + "user": { + "meta": { + "included": false + } + }, + "comments": { + "data": [ + { + "type": "comments", + "id": "37" + }, + { + "type": "comments", + "id": "38" + } + ] + } + } + }, + { + "id": "20", + "type": "posts", + "attributes": { + "title": "Some Post", + "body": "awesome content", + "created_at": "2017-07-01 05:00:00 UTC", + "updated_at": "2017-07-01 05:00:00 UTC" + }, + "relationships": { + "user": { + "meta": { + "included": false + } + }, + "comments": { + "data": [ + { + "type": "comments", + "id": "39" + }, + { + "type": "comments", + "id": "40" + } + ] + } + } + }, + { + "id": "1", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "meta": { + "included": false + } + } + } + }, + { + "id": "2", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "meta": { + "included": false + } + } + } + }, + { + "id": "3", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "meta": { + "included": false + } + } + } + }, + { + "id": "4", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "meta": { + "included": false + } + } + } + }, + { + "id": "5", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "meta": { + "included": false + } + } + } + }, + { + "id": "6", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "meta": { + "included": false + } + } + } + }, + { + "id": "7", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "meta": { + "included": false + } + } + } + }, + { + "id": "8", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "meta": { + "included": false + } + } + } + }, + { + "id": "9", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "meta": { + "included": false + } + } + } + }, + { + "id": "10", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "meta": { + "included": false + } + } + } + }, + { + "id": "11", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "meta": { + "included": false + } + } + } + }, + { + "id": "12", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "meta": { + "included": false + } + } + } + }, + { + "id": "13", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "meta": { + "included": false + } + } + } + }, + { + "id": "14", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "meta": { + "included": false + } + } + } + }, + { + "id": "15", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "meta": { + "included": false + } + } + } + }, + { + "id": "16", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "meta": { + "included": false + } + } + } + }, + { + "id": "17", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "meta": { + "included": false + } + } + } + }, + { + "id": "18", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "meta": { + "included": false + } + } + } + }, + { + "id": "19", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "meta": { + "included": false + } + } + } + }, + { + "id": "20", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "meta": { + "included": false + } + } + } + }, + { + "id": "21", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "meta": { + "included": false + } + } + } + }, + { + "id": "22", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "meta": { + "included": false + } + } + } + }, + { + "id": "23", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "meta": { + "included": false + } + } + } + }, + { + "id": "24", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "meta": { + "included": false + } + } + } + }, + { + "id": "25", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "meta": { + "included": false + } + } + } + }, + { + "id": "26", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "meta": { + "included": false + } + } + } + }, + { + "id": "27", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "meta": { + "included": false + } + } + } + }, + { + "id": "28", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "meta": { + "included": false + } + } + } + }, + { + "id": "29", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "meta": { + "included": false + } + } + } + }, + { + "id": "30", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "meta": { + "included": false + } + } + } + }, + { + "id": "31", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "meta": { + "included": false + } + } + } + }, + { + "id": "32", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "meta": { + "included": false + } + } + } + }, + { + "id": "33", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "meta": { + "included": false + } + } + } + }, + { + "id": "34", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "meta": { + "included": false + } + } + } + }, + { + "id": "35", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "meta": { + "included": false + } + } + } + }, + { + "id": "36", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "meta": { + "included": false + } + } + } + }, + { + "id": "37", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "meta": { + "included": false + } + } + } + }, + { + "id": "38", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "meta": { + "included": false + } + } + } + }, + { + "id": "39", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "meta": { + "included": false + } + } + } + }, + { + "id": "40", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "meta": { + "included": false + } + } + } + } + ] +} \ No newline at end of file From 0f8d447969545b499d0482cf59251882aa9bed0b Mon Sep 17 00:00:00 2001 From: Benjamin Fleischer Date: Fri, 13 Oct 2017 22:24:18 -0500 Subject: [PATCH 06/13] Compare bash --- benchmarks/serialization_libraries/compare.sh | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 benchmarks/serialization_libraries/compare.sh diff --git a/benchmarks/serialization_libraries/compare.sh b/benchmarks/serialization_libraries/compare.sh new file mode 100644 index 00000000..9e057355 --- /dev/null +++ b/benchmarks/serialization_libraries/compare.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash + +set -o pipefail + +DEBUG="${DEBUG:-false}" + +if ! command -v jq &>/dev/null; then + npm install -g jq +fi + +get_for_file() { + local path + path="$1" + result="$(cat ${path})" + echo "$result" +} + +compare_files() { + local actual + local expected + actual="$1" + expected="$2" + if [ "$DEBUG" = "true" ]; then get_for_file "${expected}" >&2; fi + diff --side-by-side \ + <(jq '.' -S <(get_for_file "${expected}")) \ + <(jq '.' -S <(get_for_file "${actual}")) +} +echo + +compare_files support/json_document-ams.json support/json_document-jsonapi_rb.json From 38af67024a22efc350b7e1d64645334d72b79432 Mon Sep 17 00:00:00 2001 From: Benjamin Fleischer Date: Fri, 13 Oct 2017 22:28:08 -0500 Subject: [PATCH 07/13] Make all ids increment for uniquness and sortability --- .../support/bench_helper.rb | 10 +- .../support/json_document-ams.json | 1056 ++++++++--------- .../support/json_document-jsonapi_rb.json | 926 +++++++-------- 3 files changed, 998 insertions(+), 994 deletions(-) diff --git a/benchmarks/serialization_libraries/support/bench_helper.rb b/benchmarks/serialization_libraries/support/bench_helper.rb index bedebd3f..2ef10ed7 100644 --- a/benchmarks/serialization_libraries/support/bench_helper.rb +++ b/benchmarks/serialization_libraries/support/bench_helper.rb @@ -14,12 +14,16 @@ module BenchHelper } anchor_time = Time.new(2017,7,1).utc - user = User.create(first_name: 'Diana', last_name: 'Prince', birthday: anchor_time, created_at: anchor_time, updated_at: anchor_time) + id = 1 + user = User.create!(id: id, first_name: 'Diana', last_name: 'Prince', birthday: anchor_time, created_at: anchor_time, updated_at: anchor_time) + id += 1 data_config[:posts].times do - post = Post.create(user_id: user.id, title: 'Some Post', body: 'awesome content', created_at: anchor_time, updated_at: anchor_time) + post = Post.create!(id: id, user_id: user.id, title: 'Some Post', body: 'awesome content', created_at: anchor_time, updated_at: anchor_time) + id += 1 data_config[:comments_per_post].times do - Comment.create(author: 'me', comment: 'nice blog', post_id: post.id, created_at: anchor_time, updated_at: anchor_time) + Comment.create!(id: id, author: 'me', comment: 'nice blog', post_id: post.id, created_at: anchor_time, updated_at: anchor_time) + id += 1 end end end diff --git a/benchmarks/serialization_libraries/support/json_document-ams.json b/benchmarks/serialization_libraries/support/json_document-ams.json index 7bcdbc84..f1f060eb 100644 --- a/benchmarks/serialization_libraries/support/json_document-ams.json +++ b/benchmarks/serialization_libraries/support/json_document-ams.json @@ -12,153 +12,91 @@ "relationships": { "posts": { "data": [ - { - "id": "1", - "type": "posts" - }, { "id": "2", "type": "posts" }, - { - "id": "3", - "type": "posts" - }, - { - "id": "4", - "type": "posts" - }, { "id": "5", "type": "posts" }, - { - "id": "6", - "type": "posts" - }, - { - "id": "7", - "type": "posts" - }, { "id": "8", "type": "posts" }, - { - "id": "9", - "type": "posts" - }, - { - "id": "10", - "type": "posts" - }, { "id": "11", "type": "posts" }, - { - "id": "12", - "type": "posts" - }, - { - "id": "13", - "type": "posts" - }, { "id": "14", "type": "posts" }, - { - "id": "15", - "type": "posts" - }, - { - "id": "16", - "type": "posts" - }, { "id": "17", "type": "posts" }, - { - "id": "18", - "type": "posts" - }, - { - "id": "19", - "type": "posts" - }, { "id": "20", "type": "posts" + }, + { + "id": "23", + "type": "posts" + }, + { + "id": "26", + "type": "posts" + }, + { + "id": "29", + "type": "posts" + }, + { + "id": "32", + "type": "posts" + }, + { + "id": "35", + "type": "posts" + }, + { + "id": "38", + "type": "posts" + }, + { + "id": "41", + "type": "posts" + }, + { + "id": "44", + "type": "posts" + }, + { + "id": "47", + "type": "posts" + }, + { + "id": "50", + "type": "posts" + }, + { + "id": "53", + "type": "posts" + }, + { + "id": "56", + "type": "posts" + }, + { + "id": "59", + "type": "posts" } ] } } }, "included": [ - { - "id": "1", - "type": "posts", - "attributes": { - "title": "Some Post", - "body": "awesome content", - "created_at": "2017-07-01 05:00:00 UTC", - "updated_at": "2017-07-01 05:00:00 UTC" - }, - "relationships": { - "user": { - "data": { - "id": "1", - "type": "users" - } - }, - "comments": { - "data": [ - { - "id": "1", - "type": "comments" - }, - { - "id": "2", - "type": "comments" - } - ] - } - } - }, - { - "id": "1", - "type": "comments", - "attributes": { - "author": "me", - "comment": "nice blog" - }, - "relationships": { - "post": { - "data": { - "id": "1", - "type": "posts" - } - } - } - }, - { - "id": "2", - "type": "comments", - "attributes": { - "author": "me", - "comment": "nice blog" - }, - "relationships": { - "post": { - "data": { - "id": "1", - "type": "posts" - } - } - } - }, { "id": "2", "type": "posts", @@ -222,7 +160,7 @@ } }, { - "id": "3", + "id": "5", "type": "posts", "attributes": { "title": "Some Post", @@ -240,33 +178,17 @@ "comments": { "data": [ { - "id": "5", + "id": "6", "type": "comments" }, { - "id": "6", + "id": "7", "type": "comments" } ] } } }, - { - "id": "5", - "type": "comments", - "attributes": { - "author": "me", - "comment": "nice blog" - }, - "relationships": { - "post": { - "data": { - "id": "3", - "type": "posts" - } - } - } - }, { "id": "6", "type": "comments", @@ -277,42 +199,12 @@ "relationships": { "post": { "data": { - "id": "3", + "id": "5", "type": "posts" } } } }, - { - "id": "4", - "type": "posts", - "attributes": { - "title": "Some Post", - "body": "awesome content", - "created_at": "2017-07-01 05:00:00 UTC", - "updated_at": "2017-07-01 05:00:00 UTC" - }, - "relationships": { - "user": { - "data": { - "id": "1", - "type": "users" - } - }, - "comments": { - "data": [ - { - "id": "7", - "type": "comments" - }, - { - "id": "8", - "type": "comments" - } - ] - } - } - }, { "id": "7", "type": "comments", @@ -323,7 +215,7 @@ "relationships": { "post": { "data": { - "id": "4", + "id": "5", "type": "posts" } } @@ -331,22 +223,6 @@ }, { "id": "8", - "type": "comments", - "attributes": { - "author": "me", - "comment": "nice blog" - }, - "relationships": { - "post": { - "data": { - "id": "4", - "type": "posts" - } - } - } - }, - { - "id": "5", "type": "posts", "attributes": { "title": "Some Post", @@ -385,7 +261,7 @@ "relationships": { "post": { "data": { - "id": "5", + "id": "8", "type": "posts" } } @@ -401,14 +277,14 @@ "relationships": { "post": { "data": { - "id": "5", + "id": "8", "type": "posts" } } } }, { - "id": "6", + "id": "11", "type": "posts", "attributes": { "title": "Some Post", @@ -426,33 +302,17 @@ "comments": { "data": [ { - "id": "11", + "id": "12", "type": "comments" }, { - "id": "12", + "id": "13", "type": "comments" } ] } } }, - { - "id": "11", - "type": "comments", - "attributes": { - "author": "me", - "comment": "nice blog" - }, - "relationships": { - "post": { - "data": { - "id": "6", - "type": "posts" - } - } - } - }, { "id": "12", "type": "comments", @@ -463,42 +323,12 @@ "relationships": { "post": { "data": { - "id": "6", + "id": "11", "type": "posts" } } } }, - { - "id": "7", - "type": "posts", - "attributes": { - "title": "Some Post", - "body": "awesome content", - "created_at": "2017-07-01 05:00:00 UTC", - "updated_at": "2017-07-01 05:00:00 UTC" - }, - "relationships": { - "user": { - "data": { - "id": "1", - "type": "users" - } - }, - "comments": { - "data": [ - { - "id": "13", - "type": "comments" - }, - { - "id": "14", - "type": "comments" - } - ] - } - } - }, { "id": "13", "type": "comments", @@ -509,7 +339,7 @@ "relationships": { "post": { "data": { - "id": "7", + "id": "11", "type": "posts" } } @@ -517,22 +347,6 @@ }, { "id": "14", - "type": "comments", - "attributes": { - "author": "me", - "comment": "nice blog" - }, - "relationships": { - "post": { - "data": { - "id": "7", - "type": "posts" - } - } - } - }, - { - "id": "8", "type": "posts", "attributes": { "title": "Some Post", @@ -571,7 +385,7 @@ "relationships": { "post": { "data": { - "id": "8", + "id": "14", "type": "posts" } } @@ -587,14 +401,14 @@ "relationships": { "post": { "data": { - "id": "8", + "id": "14", "type": "posts" } } } }, { - "id": "9", + "id": "17", "type": "posts", "attributes": { "title": "Some Post", @@ -612,33 +426,17 @@ "comments": { "data": [ { - "id": "17", + "id": "18", "type": "comments" }, { - "id": "18", + "id": "19", "type": "comments" } ] } } }, - { - "id": "17", - "type": "comments", - "attributes": { - "author": "me", - "comment": "nice blog" - }, - "relationships": { - "post": { - "data": { - "id": "9", - "type": "posts" - } - } - } - }, { "id": "18", "type": "comments", @@ -649,42 +447,12 @@ "relationships": { "post": { "data": { - "id": "9", + "id": "17", "type": "posts" } } } }, - { - "id": "10", - "type": "posts", - "attributes": { - "title": "Some Post", - "body": "awesome content", - "created_at": "2017-07-01 05:00:00 UTC", - "updated_at": "2017-07-01 05:00:00 UTC" - }, - "relationships": { - "user": { - "data": { - "id": "1", - "type": "users" - } - }, - "comments": { - "data": [ - { - "id": "19", - "type": "comments" - }, - { - "id": "20", - "type": "comments" - } - ] - } - } - }, { "id": "19", "type": "comments", @@ -695,7 +463,7 @@ "relationships": { "post": { "data": { - "id": "10", + "id": "17", "type": "posts" } } @@ -703,22 +471,6 @@ }, { "id": "20", - "type": "comments", - "attributes": { - "author": "me", - "comment": "nice blog" - }, - "relationships": { - "post": { - "data": { - "id": "10", - "type": "posts" - } - } - } - }, - { - "id": "11", "type": "posts", "attributes": { "title": "Some Post", @@ -757,7 +509,7 @@ "relationships": { "post": { "data": { - "id": "11", + "id": "20", "type": "posts" } } @@ -773,14 +525,14 @@ "relationships": { "post": { "data": { - "id": "11", + "id": "20", "type": "posts" } } } }, { - "id": "12", + "id": "23", "type": "posts", "attributes": { "title": "Some Post", @@ -798,33 +550,17 @@ "comments": { "data": [ { - "id": "23", + "id": "24", "type": "comments" }, { - "id": "24", + "id": "25", "type": "comments" } ] } } }, - { - "id": "23", - "type": "comments", - "attributes": { - "author": "me", - "comment": "nice blog" - }, - "relationships": { - "post": { - "data": { - "id": "12", - "type": "posts" - } - } - } - }, { "id": "24", "type": "comments", @@ -835,42 +571,12 @@ "relationships": { "post": { "data": { - "id": "12", + "id": "23", "type": "posts" } } } }, - { - "id": "13", - "type": "posts", - "attributes": { - "title": "Some Post", - "body": "awesome content", - "created_at": "2017-07-01 05:00:00 UTC", - "updated_at": "2017-07-01 05:00:00 UTC" - }, - "relationships": { - "user": { - "data": { - "id": "1", - "type": "users" - } - }, - "comments": { - "data": [ - { - "id": "25", - "type": "comments" - }, - { - "id": "26", - "type": "comments" - } - ] - } - } - }, { "id": "25", "type": "comments", @@ -881,7 +587,7 @@ "relationships": { "post": { "data": { - "id": "13", + "id": "23", "type": "posts" } } @@ -889,22 +595,6 @@ }, { "id": "26", - "type": "comments", - "attributes": { - "author": "me", - "comment": "nice blog" - }, - "relationships": { - "post": { - "data": { - "id": "13", - "type": "posts" - } - } - } - }, - { - "id": "14", "type": "posts", "attributes": { "title": "Some Post", @@ -943,7 +633,7 @@ "relationships": { "post": { "data": { - "id": "14", + "id": "26", "type": "posts" } } @@ -959,14 +649,14 @@ "relationships": { "post": { "data": { - "id": "14", + "id": "26", "type": "posts" } } } }, { - "id": "15", + "id": "29", "type": "posts", "attributes": { "title": "Some Post", @@ -984,33 +674,17 @@ "comments": { "data": [ { - "id": "29", + "id": "30", "type": "comments" }, { - "id": "30", + "id": "31", "type": "comments" } ] } } }, - { - "id": "29", - "type": "comments", - "attributes": { - "author": "me", - "comment": "nice blog" - }, - "relationships": { - "post": { - "data": { - "id": "15", - "type": "posts" - } - } - } - }, { "id": "30", "type": "comments", @@ -1021,42 +695,12 @@ "relationships": { "post": { "data": { - "id": "15", + "id": "29", "type": "posts" } } } }, - { - "id": "16", - "type": "posts", - "attributes": { - "title": "Some Post", - "body": "awesome content", - "created_at": "2017-07-01 05:00:00 UTC", - "updated_at": "2017-07-01 05:00:00 UTC" - }, - "relationships": { - "user": { - "data": { - "id": "1", - "type": "users" - } - }, - "comments": { - "data": [ - { - "id": "31", - "type": "comments" - }, - { - "id": "32", - "type": "comments" - } - ] - } - } - }, { "id": "31", "type": "comments", @@ -1067,7 +711,7 @@ "relationships": { "post": { "data": { - "id": "16", + "id": "29", "type": "posts" } } @@ -1075,22 +719,6 @@ }, { "id": "32", - "type": "comments", - "attributes": { - "author": "me", - "comment": "nice blog" - }, - "relationships": { - "post": { - "data": { - "id": "16", - "type": "posts" - } - } - } - }, - { - "id": "17", "type": "posts", "attributes": { "title": "Some Post", @@ -1129,7 +757,7 @@ "relationships": { "post": { "data": { - "id": "17", + "id": "32", "type": "posts" } } @@ -1145,14 +773,14 @@ "relationships": { "post": { "data": { - "id": "17", + "id": "32", "type": "posts" } } } }, { - "id": "18", + "id": "35", "type": "posts", "attributes": { "title": "Some Post", @@ -1170,33 +798,17 @@ "comments": { "data": [ { - "id": "35", + "id": "36", "type": "comments" }, { - "id": "36", + "id": "37", "type": "comments" } ] } } }, - { - "id": "35", - "type": "comments", - "attributes": { - "author": "me", - "comment": "nice blog" - }, - "relationships": { - "post": { - "data": { - "id": "18", - "type": "posts" - } - } - } - }, { "id": "36", "type": "comments", @@ -1207,42 +819,12 @@ "relationships": { "post": { "data": { - "id": "18", + "id": "35", "type": "posts" } } } }, - { - "id": "19", - "type": "posts", - "attributes": { - "title": "Some Post", - "body": "awesome content", - "created_at": "2017-07-01 05:00:00 UTC", - "updated_at": "2017-07-01 05:00:00 UTC" - }, - "relationships": { - "user": { - "data": { - "id": "1", - "type": "users" - } - }, - "comments": { - "data": [ - { - "id": "37", - "type": "comments" - }, - { - "id": "38", - "type": "comments" - } - ] - } - } - }, { "id": "37", "type": "comments", @@ -1253,7 +835,7 @@ "relationships": { "post": { "data": { - "id": "19", + "id": "35", "type": "posts" } } @@ -1261,22 +843,6 @@ }, { "id": "38", - "type": "comments", - "attributes": { - "author": "me", - "comment": "nice blog" - }, - "relationships": { - "post": { - "data": { - "id": "19", - "type": "posts" - } - } - } - }, - { - "id": "20", "type": "posts", "attributes": { "title": "Some Post", @@ -1315,7 +881,7 @@ "relationships": { "post": { "data": { - "id": "20", + "id": "38", "type": "posts" } } @@ -1331,7 +897,441 @@ "relationships": { "post": { "data": { - "id": "20", + "id": "38", + "type": "posts" + } + } + } + }, + { + "id": "41", + "type": "posts", + "attributes": { + "title": "Some Post", + "body": "awesome content", + "created_at": "2017-07-01 05:00:00 UTC", + "updated_at": "2017-07-01 05:00:00 UTC" + }, + "relationships": { + "user": { + "data": { + "id": "1", + "type": "users" + } + }, + "comments": { + "data": [ + { + "id": "42", + "type": "comments" + }, + { + "id": "43", + "type": "comments" + } + ] + } + } + }, + { + "id": "42", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "data": { + "id": "41", + "type": "posts" + } + } + } + }, + { + "id": "43", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "data": { + "id": "41", + "type": "posts" + } + } + } + }, + { + "id": "44", + "type": "posts", + "attributes": { + "title": "Some Post", + "body": "awesome content", + "created_at": "2017-07-01 05:00:00 UTC", + "updated_at": "2017-07-01 05:00:00 UTC" + }, + "relationships": { + "user": { + "data": { + "id": "1", + "type": "users" + } + }, + "comments": { + "data": [ + { + "id": "45", + "type": "comments" + }, + { + "id": "46", + "type": "comments" + } + ] + } + } + }, + { + "id": "45", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "data": { + "id": "44", + "type": "posts" + } + } + } + }, + { + "id": "46", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "data": { + "id": "44", + "type": "posts" + } + } + } + }, + { + "id": "47", + "type": "posts", + "attributes": { + "title": "Some Post", + "body": "awesome content", + "created_at": "2017-07-01 05:00:00 UTC", + "updated_at": "2017-07-01 05:00:00 UTC" + }, + "relationships": { + "user": { + "data": { + "id": "1", + "type": "users" + } + }, + "comments": { + "data": [ + { + "id": "48", + "type": "comments" + }, + { + "id": "49", + "type": "comments" + } + ] + } + } + }, + { + "id": "48", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "data": { + "id": "47", + "type": "posts" + } + } + } + }, + { + "id": "49", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "data": { + "id": "47", + "type": "posts" + } + } + } + }, + { + "id": "50", + "type": "posts", + "attributes": { + "title": "Some Post", + "body": "awesome content", + "created_at": "2017-07-01 05:00:00 UTC", + "updated_at": "2017-07-01 05:00:00 UTC" + }, + "relationships": { + "user": { + "data": { + "id": "1", + "type": "users" + } + }, + "comments": { + "data": [ + { + "id": "51", + "type": "comments" + }, + { + "id": "52", + "type": "comments" + } + ] + } + } + }, + { + "id": "51", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "data": { + "id": "50", + "type": "posts" + } + } + } + }, + { + "id": "52", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "data": { + "id": "50", + "type": "posts" + } + } + } + }, + { + "id": "53", + "type": "posts", + "attributes": { + "title": "Some Post", + "body": "awesome content", + "created_at": "2017-07-01 05:00:00 UTC", + "updated_at": "2017-07-01 05:00:00 UTC" + }, + "relationships": { + "user": { + "data": { + "id": "1", + "type": "users" + } + }, + "comments": { + "data": [ + { + "id": "54", + "type": "comments" + }, + { + "id": "55", + "type": "comments" + } + ] + } + } + }, + { + "id": "54", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "data": { + "id": "53", + "type": "posts" + } + } + } + }, + { + "id": "55", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "data": { + "id": "53", + "type": "posts" + } + } + } + }, + { + "id": "56", + "type": "posts", + "attributes": { + "title": "Some Post", + "body": "awesome content", + "created_at": "2017-07-01 05:00:00 UTC", + "updated_at": "2017-07-01 05:00:00 UTC" + }, + "relationships": { + "user": { + "data": { + "id": "1", + "type": "users" + } + }, + "comments": { + "data": [ + { + "id": "57", + "type": "comments" + }, + { + "id": "58", + "type": "comments" + } + ] + } + } + }, + { + "id": "57", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "data": { + "id": "56", + "type": "posts" + } + } + } + }, + { + "id": "58", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "data": { + "id": "56", + "type": "posts" + } + } + } + }, + { + "id": "59", + "type": "posts", + "attributes": { + "title": "Some Post", + "body": "awesome content", + "created_at": "2017-07-01 05:00:00 UTC", + "updated_at": "2017-07-01 05:00:00 UTC" + }, + "relationships": { + "user": { + "data": { + "id": "1", + "type": "users" + } + }, + "comments": { + "data": [ + { + "id": "60", + "type": "comments" + }, + { + "id": "61", + "type": "comments" + } + ] + } + } + }, + { + "id": "60", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "data": { + "id": "59", + "type": "posts" + } + } + } + }, + { + "id": "61", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "data": { + "id": "59", "type": "posts" } } diff --git a/benchmarks/serialization_libraries/support/json_document-jsonapi_rb.json b/benchmarks/serialization_libraries/support/json_document-jsonapi_rb.json index 525a05a3..a4ea1106 100644 --- a/benchmarks/serialization_libraries/support/json_document-jsonapi_rb.json +++ b/benchmarks/serialization_libraries/support/json_document-jsonapi_rb.json @@ -12,120 +12,91 @@ "relationships": { "posts": { "data": [ - { - "type": "posts", - "id": "1" - }, { "type": "posts", "id": "2" }, - { - "type": "posts", - "id": "3" - }, - { - "type": "posts", - "id": "4" - }, { "type": "posts", "id": "5" }, - { - "type": "posts", - "id": "6" - }, - { - "type": "posts", - "id": "7" - }, { "type": "posts", "id": "8" }, - { - "type": "posts", - "id": "9" - }, - { - "type": "posts", - "id": "10" - }, { "type": "posts", "id": "11" }, - { - "type": "posts", - "id": "12" - }, - { - "type": "posts", - "id": "13" - }, { "type": "posts", "id": "14" }, - { - "type": "posts", - "id": "15" - }, - { - "type": "posts", - "id": "16" - }, { "type": "posts", "id": "17" }, - { - "type": "posts", - "id": "18" - }, - { - "type": "posts", - "id": "19" - }, { "type": "posts", "id": "20" + }, + { + "type": "posts", + "id": "23" + }, + { + "type": "posts", + "id": "26" + }, + { + "type": "posts", + "id": "29" + }, + { + "type": "posts", + "id": "32" + }, + { + "type": "posts", + "id": "35" + }, + { + "type": "posts", + "id": "38" + }, + { + "type": "posts", + "id": "41" + }, + { + "type": "posts", + "id": "44" + }, + { + "type": "posts", + "id": "47" + }, + { + "type": "posts", + "id": "50" + }, + { + "type": "posts", + "id": "53" + }, + { + "type": "posts", + "id": "56" + }, + { + "type": "posts", + "id": "59" } ] } } }, "included": [ - { - "id": "1", - "type": "posts", - "attributes": { - "title": "Some Post", - "body": "awesome content", - "created_at": "2017-07-01 05:00:00 UTC", - "updated_at": "2017-07-01 05:00:00 UTC" - }, - "relationships": { - "user": { - "meta": { - "included": false - } - }, - "comments": { - "data": [ - { - "type": "comments", - "id": "1" - }, - { - "type": "comments", - "id": "2" - } - ] - } - } - }, { "id": "2", "type": "posts", @@ -156,7 +127,7 @@ } }, { - "id": "3", + "id": "5", "type": "posts", "attributes": { "title": "Some Post", @@ -172,49 +143,20 @@ }, "comments": { "data": [ - { - "type": "comments", - "id": "5" - }, { "type": "comments", "id": "6" - } - ] - } - } - }, - { - "id": "4", - "type": "posts", - "attributes": { - "title": "Some Post", - "body": "awesome content", - "created_at": "2017-07-01 05:00:00 UTC", - "updated_at": "2017-07-01 05:00:00 UTC" - }, - "relationships": { - "user": { - "meta": { - "included": false - } - }, - "comments": { - "data": [ - { - "type": "comments", - "id": "7" }, { "type": "comments", - "id": "8" + "id": "7" } ] } } }, { - "id": "5", + "id": "8", "type": "posts", "attributes": { "title": "Some Post", @@ -243,7 +185,7 @@ } }, { - "id": "6", + "id": "11", "type": "posts", "attributes": { "title": "Some Post", @@ -259,49 +201,20 @@ }, "comments": { "data": [ - { - "type": "comments", - "id": "11" - }, { "type": "comments", "id": "12" - } - ] - } - } - }, - { - "id": "7", - "type": "posts", - "attributes": { - "title": "Some Post", - "body": "awesome content", - "created_at": "2017-07-01 05:00:00 UTC", - "updated_at": "2017-07-01 05:00:00 UTC" - }, - "relationships": { - "user": { - "meta": { - "included": false - } - }, - "comments": { - "data": [ - { - "type": "comments", - "id": "13" }, { "type": "comments", - "id": "14" + "id": "13" } ] } } }, { - "id": "8", + "id": "14", "type": "posts", "attributes": { "title": "Some Post", @@ -330,7 +243,7 @@ } }, { - "id": "9", + "id": "17", "type": "posts", "attributes": { "title": "Some Post", @@ -346,49 +259,20 @@ }, "comments": { "data": [ - { - "type": "comments", - "id": "17" - }, { "type": "comments", "id": "18" - } - ] - } - } - }, - { - "id": "10", - "type": "posts", - "attributes": { - "title": "Some Post", - "body": "awesome content", - "created_at": "2017-07-01 05:00:00 UTC", - "updated_at": "2017-07-01 05:00:00 UTC" - }, - "relationships": { - "user": { - "meta": { - "included": false - } - }, - "comments": { - "data": [ - { - "type": "comments", - "id": "19" }, { "type": "comments", - "id": "20" + "id": "19" } ] } } }, { - "id": "11", + "id": "20", "type": "posts", "attributes": { "title": "Some Post", @@ -417,7 +301,7 @@ } }, { - "id": "12", + "id": "23", "type": "posts", "attributes": { "title": "Some Post", @@ -433,49 +317,20 @@ }, "comments": { "data": [ - { - "type": "comments", - "id": "23" - }, { "type": "comments", "id": "24" - } - ] - } - } - }, - { - "id": "13", - "type": "posts", - "attributes": { - "title": "Some Post", - "body": "awesome content", - "created_at": "2017-07-01 05:00:00 UTC", - "updated_at": "2017-07-01 05:00:00 UTC" - }, - "relationships": { - "user": { - "meta": { - "included": false - } - }, - "comments": { - "data": [ - { - "type": "comments", - "id": "25" }, { "type": "comments", - "id": "26" + "id": "25" } ] } } }, { - "id": "14", + "id": "26", "type": "posts", "attributes": { "title": "Some Post", @@ -504,7 +359,7 @@ } }, { - "id": "15", + "id": "29", "type": "posts", "attributes": { "title": "Some Post", @@ -520,49 +375,20 @@ }, "comments": { "data": [ - { - "type": "comments", - "id": "29" - }, { "type": "comments", "id": "30" - } - ] - } - } - }, - { - "id": "16", - "type": "posts", - "attributes": { - "title": "Some Post", - "body": "awesome content", - "created_at": "2017-07-01 05:00:00 UTC", - "updated_at": "2017-07-01 05:00:00 UTC" - }, - "relationships": { - "user": { - "meta": { - "included": false - } - }, - "comments": { - "data": [ - { - "type": "comments", - "id": "31" }, { "type": "comments", - "id": "32" + "id": "31" } ] } } }, { - "id": "17", + "id": "32", "type": "posts", "attributes": { "title": "Some Post", @@ -591,7 +417,7 @@ } }, { - "id": "18", + "id": "35", "type": "posts", "attributes": { "title": "Some Post", @@ -607,49 +433,20 @@ }, "comments": { "data": [ - { - "type": "comments", - "id": "35" - }, { "type": "comments", "id": "36" - } - ] - } - } - }, - { - "id": "19", - "type": "posts", - "attributes": { - "title": "Some Post", - "body": "awesome content", - "created_at": "2017-07-01 05:00:00 UTC", - "updated_at": "2017-07-01 05:00:00 UTC" - }, - "relationships": { - "user": { - "meta": { - "included": false - } - }, - "comments": { - "data": [ - { - "type": "comments", - "id": "37" }, { "type": "comments", - "id": "38" + "id": "37" } ] } } }, { - "id": "20", + "id": "38", "type": "posts", "attributes": { "title": "Some Post", @@ -678,32 +475,205 @@ } }, { - "id": "1", - "type": "comments", + "id": "41", + "type": "posts", "attributes": { - "author": "me", - "comment": "nice blog" + "title": "Some Post", + "body": "awesome content", + "created_at": "2017-07-01 05:00:00 UTC", + "updated_at": "2017-07-01 05:00:00 UTC" }, "relationships": { - "post": { + "user": { "meta": { "included": false } + }, + "comments": { + "data": [ + { + "type": "comments", + "id": "42" + }, + { + "type": "comments", + "id": "43" + } + ] } } }, { - "id": "2", - "type": "comments", + "id": "44", + "type": "posts", "attributes": { - "author": "me", - "comment": "nice blog" + "title": "Some Post", + "body": "awesome content", + "created_at": "2017-07-01 05:00:00 UTC", + "updated_at": "2017-07-01 05:00:00 UTC" }, "relationships": { - "post": { + "user": { "meta": { "included": false } + }, + "comments": { + "data": [ + { + "type": "comments", + "id": "45" + }, + { + "type": "comments", + "id": "46" + } + ] + } + } + }, + { + "id": "47", + "type": "posts", + "attributes": { + "title": "Some Post", + "body": "awesome content", + "created_at": "2017-07-01 05:00:00 UTC", + "updated_at": "2017-07-01 05:00:00 UTC" + }, + "relationships": { + "user": { + "meta": { + "included": false + } + }, + "comments": { + "data": [ + { + "type": "comments", + "id": "48" + }, + { + "type": "comments", + "id": "49" + } + ] + } + } + }, + { + "id": "50", + "type": "posts", + "attributes": { + "title": "Some Post", + "body": "awesome content", + "created_at": "2017-07-01 05:00:00 UTC", + "updated_at": "2017-07-01 05:00:00 UTC" + }, + "relationships": { + "user": { + "meta": { + "included": false + } + }, + "comments": { + "data": [ + { + "type": "comments", + "id": "51" + }, + { + "type": "comments", + "id": "52" + } + ] + } + } + }, + { + "id": "53", + "type": "posts", + "attributes": { + "title": "Some Post", + "body": "awesome content", + "created_at": "2017-07-01 05:00:00 UTC", + "updated_at": "2017-07-01 05:00:00 UTC" + }, + "relationships": { + "user": { + "meta": { + "included": false + } + }, + "comments": { + "data": [ + { + "type": "comments", + "id": "54" + }, + { + "type": "comments", + "id": "55" + } + ] + } + } + }, + { + "id": "56", + "type": "posts", + "attributes": { + "title": "Some Post", + "body": "awesome content", + "created_at": "2017-07-01 05:00:00 UTC", + "updated_at": "2017-07-01 05:00:00 UTC" + }, + "relationships": { + "user": { + "meta": { + "included": false + } + }, + "comments": { + "data": [ + { + "type": "comments", + "id": "57" + }, + { + "type": "comments", + "id": "58" + } + ] + } + } + }, + { + "id": "59", + "type": "posts", + "attributes": { + "title": "Some Post", + "body": "awesome content", + "created_at": "2017-07-01 05:00:00 UTC", + "updated_at": "2017-07-01 05:00:00 UTC" + }, + "relationships": { + "user": { + "meta": { + "included": false + } + }, + "comments": { + "data": [ + { + "type": "comments", + "id": "60" + }, + { + "type": "comments", + "id": "61" + } + ] } } }, @@ -737,21 +707,6 @@ } } }, - { - "id": "5", - "type": "comments", - "attributes": { - "author": "me", - "comment": "nice blog" - }, - "relationships": { - "post": { - "meta": { - "included": false - } - } - } - }, { "id": "6", "type": "comments", @@ -782,21 +737,6 @@ } } }, - { - "id": "8", - "type": "comments", - "attributes": { - "author": "me", - "comment": "nice blog" - }, - "relationships": { - "post": { - "meta": { - "included": false - } - } - } - }, { "id": "9", "type": "comments", @@ -827,21 +767,6 @@ } } }, - { - "id": "11", - "type": "comments", - "attributes": { - "author": "me", - "comment": "nice blog" - }, - "relationships": { - "post": { - "meta": { - "included": false - } - } - } - }, { "id": "12", "type": "comments", @@ -872,21 +797,6 @@ } } }, - { - "id": "14", - "type": "comments", - "attributes": { - "author": "me", - "comment": "nice blog" - }, - "relationships": { - "post": { - "meta": { - "included": false - } - } - } - }, { "id": "15", "type": "comments", @@ -917,21 +827,6 @@ } } }, - { - "id": "17", - "type": "comments", - "attributes": { - "author": "me", - "comment": "nice blog" - }, - "relationships": { - "post": { - "meta": { - "included": false - } - } - } - }, { "id": "18", "type": "comments", @@ -962,21 +857,6 @@ } } }, - { - "id": "20", - "type": "comments", - "attributes": { - "author": "me", - "comment": "nice blog" - }, - "relationships": { - "post": { - "meta": { - "included": false - } - } - } - }, { "id": "21", "type": "comments", @@ -1007,21 +887,6 @@ } } }, - { - "id": "23", - "type": "comments", - "attributes": { - "author": "me", - "comment": "nice blog" - }, - "relationships": { - "post": { - "meta": { - "included": false - } - } - } - }, { "id": "24", "type": "comments", @@ -1052,21 +917,6 @@ } } }, - { - "id": "26", - "type": "comments", - "attributes": { - "author": "me", - "comment": "nice blog" - }, - "relationships": { - "post": { - "meta": { - "included": false - } - } - } - }, { "id": "27", "type": "comments", @@ -1097,21 +947,6 @@ } } }, - { - "id": "29", - "type": "comments", - "attributes": { - "author": "me", - "comment": "nice blog" - }, - "relationships": { - "post": { - "meta": { - "included": false - } - } - } - }, { "id": "30", "type": "comments", @@ -1142,21 +977,6 @@ } } }, - { - "id": "32", - "type": "comments", - "attributes": { - "author": "me", - "comment": "nice blog" - }, - "relationships": { - "post": { - "meta": { - "included": false - } - } - } - }, { "id": "33", "type": "comments", @@ -1187,21 +1007,6 @@ } } }, - { - "id": "35", - "type": "comments", - "attributes": { - "author": "me", - "comment": "nice blog" - }, - "relationships": { - "post": { - "meta": { - "included": false - } - } - } - }, { "id": "36", "type": "comments", @@ -1232,21 +1037,6 @@ } } }, - { - "id": "38", - "type": "comments", - "attributes": { - "author": "me", - "comment": "nice blog" - }, - "relationships": { - "post": { - "meta": { - "included": false - } - } - } - }, { "id": "39", "type": "comments", @@ -1276,6 +1066,216 @@ } } } + }, + { + "id": "42", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "meta": { + "included": false + } + } + } + }, + { + "id": "43", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "meta": { + "included": false + } + } + } + }, + { + "id": "45", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "meta": { + "included": false + } + } + } + }, + { + "id": "46", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "meta": { + "included": false + } + } + } + }, + { + "id": "48", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "meta": { + "included": false + } + } + } + }, + { + "id": "49", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "meta": { + "included": false + } + } + } + }, + { + "id": "51", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "meta": { + "included": false + } + } + } + }, + { + "id": "52", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "meta": { + "included": false + } + } + } + }, + { + "id": "54", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "meta": { + "included": false + } + } + } + }, + { + "id": "55", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "meta": { + "included": false + } + } + } + }, + { + "id": "57", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "meta": { + "included": false + } + } + } + }, + { + "id": "58", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "meta": { + "included": false + } + } + } + }, + { + "id": "60", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "meta": { + "included": false + } + } + } + }, + { + "id": "61", + "type": "comments", + "attributes": { + "author": "me", + "comment": "nice blog" + }, + "relationships": { + "post": { + "meta": { + "included": false + } + } + } } ] } \ No newline at end of file From 9a58ab100079b5e4413121ae29c265b22da50be9 Mon Sep 17 00:00:00 2001 From: Benjamin Fleischer Date: Fri, 13 Oct 2017 22:43:12 -0500 Subject: [PATCH 08/13] Compare by pattern --- benchmarks/serialization_libraries/compare.sh | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/benchmarks/serialization_libraries/compare.sh b/benchmarks/serialization_libraries/compare.sh index 9e057355..45afbbeb 100644 --- a/benchmarks/serialization_libraries/compare.sh +++ b/benchmarks/serialization_libraries/compare.sh @@ -18,13 +18,19 @@ get_for_file() { compare_files() { local actual local expected + local pattern actual="$1" expected="$2" + pattern="$3" + if [ "$DEBUG" = "true" ]; then get_for_file "${expected}" >&2; fi - diff --side-by-side \ - <(jq '.' -S <(get_for_file "${expected}")) \ - <(jq '.' -S <(get_for_file "${actual}")) + diff --side-by-side --suppress-common-lines \ + <(jq "${pattern}" -S <(get_for_file "${expected}")) \ + <(jq "${pattern}" -S <(get_for_file "${actual}")) } echo -compare_files support/json_document-ams.json support/json_document-jsonapi_rb.json +echo "data" +compare_files support/json_document-ams.json support/json_document-jsonapi_rb.json ".data" +echo "included" +compare_files support/json_document-ams.json support/json_document-jsonapi_rb.json ".included" From 4bb5272b77842dd59929fce51061688a24e5456f Mon Sep 17 00:00:00 2001 From: Benjamin Fleischer Date: Fri, 13 Oct 2017 22:53:55 -0500 Subject: [PATCH 09/13] Fancier compare --- benchmarks/serialization_libraries/compare.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/benchmarks/serialization_libraries/compare.sh b/benchmarks/serialization_libraries/compare.sh index 45afbbeb..ca6228f3 100644 --- a/benchmarks/serialization_libraries/compare.sh +++ b/benchmarks/serialization_libraries/compare.sh @@ -24,7 +24,7 @@ compare_files() { pattern="$3" if [ "$DEBUG" = "true" ]; then get_for_file "${expected}" >&2; fi - diff --side-by-side --suppress-common-lines \ + diff --side-by-side \ <(jq "${pattern}" -S <(get_for_file "${expected}")) \ <(jq "${pattern}" -S <(get_for_file "${actual}")) } @@ -33,4 +33,6 @@ echo echo "data" compare_files support/json_document-ams.json support/json_document-jsonapi_rb.json ".data" echo "included" -compare_files support/json_document-ams.json support/json_document-jsonapi_rb.json ".included" +# compare_files support/json_document-ams.json support/json_document-jsonapi_rb.json ".included | .[] | select(.type == \"posts\")" +# compare_files support/json_document-ams.json support/json_document-jsonapi_rb.json ".included | .[] | select(.type == \"comments\")" +compare_files support/json_document-ams.json support/json_document-jsonapi_rb.json ".included | .[] | select(.type != \"comments\", .type != \"posts\")" From 68720cef4ded799331829dcee4fe87dde77788d6 Mon Sep 17 00:00:00 2001 From: Benjamin Fleischer Date: Fri, 13 Oct 2017 23:16:58 -0500 Subject: [PATCH 10/13] Confirmed difference from jsonapi vs AMS not significant pretty clear now that the ONLY difference rendering a `user` with `include: 'posts.comments'` is that the included post's user relationship in jsonapirb is `meta: { included: false }` and AMS is `data: { id: 1, type: users}` which I guess is to avoid the user's post's comment from looking up the user? similarly, the included comment's post relationship for jsonapi-rb is `meta: { included: false}` and AMS is `data: { id: 2, type: posts }` took a bit of jq and diff to figure this out --- benchmarks/serialization_libraries/compare.sh | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/benchmarks/serialization_libraries/compare.sh b/benchmarks/serialization_libraries/compare.sh index ca6228f3..a2f61c7f 100644 --- a/benchmarks/serialization_libraries/compare.sh +++ b/benchmarks/serialization_libraries/compare.sh @@ -30,9 +30,13 @@ compare_files() { } echo -echo "data" +echo "-------------------------------------data" compare_files support/json_document-ams.json support/json_document-jsonapi_rb.json ".data" -echo "included" -# compare_files support/json_document-ams.json support/json_document-jsonapi_rb.json ".included | .[] | select(.type == \"posts\")" -# compare_files support/json_document-ams.json support/json_document-jsonapi_rb.json ".included | .[] | select(.type == \"comments\")" -compare_files support/json_document-ams.json support/json_document-jsonapi_rb.json ".included | .[] | select(.type != \"comments\", .type != \"posts\")" +echo "-------------------------------------included posts" +compare_files support/json_document-ams.json support/json_document-jsonapi_rb.json ".included | .[] | select(.type == \"posts\")" +echo "-------------------------------------included comments" +compare_files support/json_document-ams.json support/json_document-jsonapi_rb.json ".included | .[] | select(.type == \"comments\")" +echo "-------------------------------------included types: ams" +jq '.included | .[] | .type' -S < support/json_document-ams.json | sort -u +echo "-------------------------------------included types: jsonapi_rb" +jq '.included | .[] | .type' -S < support/json_document-jsonapi_rb.json | sort -u From 89cbb28cfa784248d26db2bc3cdad62647baa7cd Mon Sep 17 00:00:00 2001 From: Benjamin Fleischer Date: Thu, 19 Oct 2017 10:07:41 -0500 Subject: [PATCH 11/13] Make CI no-op --- .travis.yml | 10 ++++++++++ appveyor.yml | 11 +++++++++++ 2 files changed, 21 insertions(+) create mode 100644 .travis.yml create mode 100644 appveyor.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..b48fe610 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,10 @@ +language: ruby + +sudo: false + +cache: + directories: + - vendor/bundle + +script: + - true diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 00000000..aabf26a6 --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,11 @@ +version: 1.0.{build}-{branch} + +skip_tags: true + +cache: + - vendor/bundle + +test_script: + - true + +build: off From 0de40a4cbb7bb5df363aacab9477b88006904702 Mon Sep 17 00:00:00 2001 From: Benjamin Fleischer Date: Thu, 19 Oct 2017 10:17:38 -0500 Subject: [PATCH 12/13] Give compare.sh execute --- benchmarks/serialization_libraries/compare.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 benchmarks/serialization_libraries/compare.sh diff --git a/benchmarks/serialization_libraries/compare.sh b/benchmarks/serialization_libraries/compare.sh old mode 100644 new mode 100755 From 2c21197bddc49f8cb87d6d07bd26f8ed8bbc084b Mon Sep 17 00:00:00 2001 From: Benjamin Fleischer Date: Thu, 19 Oct 2017 10:33:10 -0500 Subject: [PATCH 13/13] Document compare.sh --- benchmarks/serialization_libraries/compare.sh | 182 +++++++++++++++++- 1 file changed, 181 insertions(+), 1 deletion(-) diff --git a/benchmarks/serialization_libraries/compare.sh b/benchmarks/serialization_libraries/compare.sh index a2f61c7f..334b0649 100755 --- a/benchmarks/serialization_libraries/compare.sh +++ b/benchmarks/serialization_libraries/compare.sh @@ -1,4 +1,184 @@ #!/usr/bin/env bash +# +# Looks for significant differences between jsonapi-rb vs. ams serialization. +# +# Strategy: +# 1. The data being serialized is the same every time. +# i.e. All ids and timestamps or otherwise variable fields being serialized +# are always the same. +# 2. Compare the data in a way that accounts for the order different resources are included. +# 1. Compare the .data members, sort keys. +# 2. Compare the .included posts, sort keys. +# 3. Compare the .included comments, sort keys. +# 4. Confirm the included members are all either posts or comments. +# +# Depends on: +# jq: installed via npm +# diff: installed on system +# +# Usage: +# ./compare.sh +# +# Example output (abridged): +# +# -------------------------------------data (user) +# { { +# "attributes": { "attributes": { +# "birthday": "2017-07-01 05:00:00 UTC", "birthday": "2017-07-01 05:00:00 UTC", +# "created_at": "2017-07-01 05:00:00 UTC", "created_at": "2017-07-01 05:00:00 UTC", +# "first_name": "Diana", "first_name": "Diana", +# "last_name": "Prince", "last_name": "Prince", +# "updated_at": "2017-07-01 05:00:00 UTC" "updated_at": "2017-07-01 05:00:00 UTC" +# }, }, +# "id": "1", "id": "1", +# "relationships": { "relationships": { +# "posts": { "posts": { +# "data": [ "data": [ +# { { +# "id": "2", "id": "2", +# "type": "posts" "type": "posts" +# }, }, +# { { +# "id": "5", "id": "5", +# "type": "posts" "type": "posts" +# } } +# ] ] +# } } +# }, }, +# "type": "users" "type": "users" +# } } +# -------------------------------------included posts +# { { +# "attributes": { "attributes": { +# "body": "awesome content", "body": "awesome content", +# "created_at": "2017-07-01 05:00:00 UTC", "created_at": "2017-07-01 05:00:00 UTC", +# "title": "Some Post", "title": "Some Post", +# "updated_at": "2017-07-01 05:00:00 UTC" "updated_at": "2017-07-01 05:00:00 UTC" +# }, }, +# "id": "2", "id": "2", +# "relationships": { "relationships": { +# "comments": { "comments": { +# "data": [ "data": [ +# { { +# "id": "3", "id": "3", +# "type": "comments" "type": "comments" +# }, }, +# { { +# "id": "4", "id": "4", +# "type": "comments" "type": "comments" +# } } +# ] ] +# }, }, +# "user": { "user": { +# "meta": { | "data": { +# "included": false | "id": "1", +# > "type": "users" +# } } +# } } +# }, }, +# "type": "posts" "type": "posts" +# } } +# { { +# "attributes": { "attributes": { +# "body": "awesome content", "body": "awesome content", +# "created_at": "2017-07-01 05:00:00 UTC", "created_at": "2017-07-01 05:00:00 UTC", +# "title": "Some Post", "title": "Some Post", +# "updated_at": "2017-07-01 05:00:00 UTC" "updated_at": "2017-07-01 05:00:00 UTC" +# }, }, +# "id": "5", "id": "5", +# "relationships": { "relationships": { +# "comments": { "comments": { +# "data": [ "data": [ +# { { +# "id": "6", "id": "6", +# "type": "comments" "type": "comments" +# }, }, +# { { +# "id": "7", "id": "7", +# "type": "comments" "type": "comments" +# } } +# ] ] +# }, }, +# "user": { "user": { +# "meta": { | "data": { +# "included": false | "id": "1", +# > "type": "users" +# } } +# } } +# }, }, +# "type": "posts" "type": "posts" +# } } +# -------------------------------------included comments +# { { +# "attributes": { "attributes": { +# "author": "me", "author": "me", +# "comment": "nice blog" "comment": "nice blog" +# }, }, +# "id": "3", "id": "3", +# "relationships": { "relationships": { +# "post": { "post": { +# "meta": { | "data": { +# "included": false | "id": "2", +# > "type": "posts" +# } } +# } } +# }, }, +# "type": "comments" "type": "comments" +# } } +# { { +# "attributes": { "attributes": { +# "author": "me", "author": "me", +# "comment": "nice blog" "comment": "nice blog" +# }, }, +# "id": "4", "id": "4", +# "relationships": { "relationships": { +# "post": { "post": { +# "meta": { | "data": { +# "included": false | "id": "2", +# > "type": "posts" +# } } +# } } +# }, }, +# "type": "comments" "type": "comments" +# } } +# { { +# "attributes": { "attributes": { +# "author": "me", "author": "me", +# "comment": "nice blog" "comment": "nice blog" +# }, }, +# "id": "6", "id": "6", +# "relationships": { "relationships": { +# "post": { "post": { +# "meta": { | "data": { +# "included": false | "id": "5", +# > "type": "posts" +# } } +# } } +# }, }, +# "type": "comments" "type": "comments" +# } } +# { { +# "attributes": { "attributes": { +# "author": "me", "author": "me", +# "comment": "nice blog" "comment": "nice blog" +# }, }, +# "id": "7", "id": "7", +# "relationships": { "relationships": { +# "post": { "post": { +# "meta": { | "data": { +# "included": false | "id": "5", +# > "type": "posts" +# } } +# } } +# }, }, +# "type": "comments" "type": "comments" +# } } +# -------------------------------------included types: ams +# "comments" +# "posts" +# -------------------------------------included types: jsonapi_rb +# "comments" +# "posts" set -o pipefail @@ -30,7 +210,7 @@ compare_files() { } echo -echo "-------------------------------------data" +echo "-------------------------------------data (user)" compare_files support/json_document-ams.json support/json_document-jsonapi_rb.json ".data" echo "-------------------------------------included posts" compare_files support/json_document-ams.json support/json_document-jsonapi_rb.json ".included | .[] | select(.type == \"posts\")"