panko_serializer 0.8.3 → 0.8.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +4 -4
  3. data/ext/panko_serializer/attributes_writer/active_record.c +2 -29
  4. data/ext/panko_serializer/attributes_writer/type_cast/type_cast.c +24 -13
  5. data/lib/panko/version.rb +1 -1
  6. metadata +3 -72
  7. data/.clang-format +0 -3
  8. data/.github/dependabot.yml +0 -6
  9. data/.github/workflows/docs.yml +0 -39
  10. data/.github/workflows/lint.yml +0 -30
  11. data/.github/workflows/ruby.yml +0 -51
  12. data/.gitignore +0 -20
  13. data/.rspec +0 -2
  14. data/.rubocop.yml +0 -37
  15. data/Appraisals +0 -29
  16. data/Gemfile +0 -36
  17. data/Rakefile +0 -93
  18. data/benchmarks/BENCHMARKS.md +0 -48
  19. data/benchmarks/allocs.rb +0 -23
  20. data/benchmarks/app.rb +0 -11
  21. data/benchmarks/benchmarking_support.rb +0 -44
  22. data/benchmarks/bm_ams_0_10.rb +0 -43
  23. data/benchmarks/bm_object_writer.rb +0 -65
  24. data/benchmarks/bm_panko_json.rb +0 -60
  25. data/benchmarks/bm_panko_object.rb +0 -46
  26. data/benchmarks/bm_plain_object.rb +0 -99
  27. data/benchmarks/bm_serialization_descriptor.rb +0 -76
  28. data/benchmarks/bm_serializer_resolver.rb +0 -22
  29. data/benchmarks/bm_to_object.rb +0 -81
  30. data/benchmarks/profile.rb +0 -86
  31. data/benchmarks/sanity.rb +0 -83
  32. data/benchmarks/setup.rb +0 -56
  33. data/benchmarks/type_casts/bm_active_record.rb +0 -58
  34. data/benchmarks/type_casts/bm_panko.rb +0 -65
  35. data/benchmarks/type_casts/support.rb +0 -27
  36. data/docs/docs/associations.md +0 -107
  37. data/docs/docs/attributes.md +0 -143
  38. data/docs/docs/design-choices.md +0 -127
  39. data/docs/docs/getting-started.md +0 -70
  40. data/docs/docs/introduction.md +0 -13
  41. data/docs/docs/performance.md +0 -32
  42. data/docs/docs/response-bag.md +0 -83
  43. data/docs/docusaurus.config.js +0 -86
  44. data/docs/package-lock.json +0 -15994
  45. data/docs/package.json +0 -21
  46. data/docs/sidebars.json +0 -15
  47. data/docs/src/css/customTheme.css +0 -9
  48. data/docs/static/.DS_Store +0 -0
  49. data/docs/static/CNAME +0 -1
  50. data/docs/static/css/custom.css +0 -51
  51. data/docs/static/img/favicon.ico +0 -0
  52. data/docs/static/img/oss_logo.png +0 -0
  53. data/docs/static/img/undraw_code_review.svg +0 -1
  54. data/docs/static/img/undraw_monitor.svg +0 -1
  55. data/docs/static/img/undraw_note_list.svg +0 -1
  56. data/docs/static/img/undraw_online.svg +0 -1
  57. data/docs/static/img/undraw_open_source.svg +0 -1
  58. data/docs/static/img/undraw_operating_system.svg +0 -1
  59. data/docs/static/img/undraw_react.svg +0 -1
  60. data/docs/static/img/undraw_tweetstorm.svg +0 -1
  61. data/docs/static/img/undraw_youtube_tutorial.svg +0 -1
  62. data/docs/static/index.html +0 -14
  63. data/gemfiles/7.0.0.gemfile +0 -39
  64. data/gemfiles/7.0.0.gemfile.lock +0 -176
  65. data/gemfiles/7.1.0.gemfile +0 -39
  66. data/gemfiles/7.1.0.gemfile.lock +0 -198
  67. data/gemfiles/7.2.0.gemfile +0 -39
  68. data/gemfiles/7.2.0.gemfile.lock +0 -198
  69. data/gemfiles/8.0.0.gemfile +0 -39
  70. data/gemfiles/8.0.0.gemfile.lock +0 -219
  71. data/panko_serializer.gemspec +0 -36
@@ -1,48 +0,0 @@
1
- ## Initial state
2
- ```
3
- Native_Posts_2300 57 ip/s 13802 allocs/op
4
- Native_Posts_50 2956 ip/s 302 allocs/op
5
-
6
- AMS_Simple_Posts_2300 21 ip/s 94309 allocs/op
7
- AMS_Simple_Posts_50 1008 ip/s 2059 allocs/op
8
- AMS_HasOne_Posts_2300 9 ip/s 147209 allocs/op
9
- AMS_HasOne_Posts_50 451 ip/s 3209 allocs/op
10
-
11
- Panko_HasOne_Posts_2300 164 ip/s 2372 allocs/op
12
- Panko_HasOne_Posts_50 6118 ip/s 122 allocs/op
13
- Panko_Reused_HasOne_Posts_2300 178 ip/s 2303 allocs/op
14
- Panko_Reused_HasOne_Posts_50 8203 ip/s 53 allocs/op
15
-
16
- Panko_Simple_Posts_2300 150 ip/s 2372 allocs/op
17
- Panko_Simple_Posts_50 5639 ip/s 122 allocs/op
18
- Panko_Reused_Simple_Posts_2300 180 ip/s 2303 allocs/op
19
- Panko_Reused_Simple_Posts_50 8388 ip/s 53 allocs/op
20
- ```
21
-
22
- ## Refactorings, method call support, combining
23
-
24
- ### class eval
25
- ```
26
- Panko_HasOne_Posts_2300 64 ip/s 9477 allocs/op
27
- Panko_HasOne_Posts_50 2397 ip/s 477 allocs/op
28
- Panko_Reused_HasOne_Posts_2300 70 ip/s 9423 allocs/op
29
- Panko_Reused_HasOne_Posts_50 2596 ip/s 423 allocs/op
30
-
31
- Panko_Simple_Posts_2300 191 ip/s 2472 allocs/op
32
- Panko_Simple_Posts_50 5128 ip/s 222 allocs/op
33
- Panko_Reused_Simple_Posts_2300 180 ip/s 2418 allocs/op
34
- Panko_Reused_Simple_Posts_50 5534 ip/s 168 allocs/op
35
- ```
36
-
37
- ### instance eval
38
- ```
39
- Panko_HasOne_Posts_2300 60 ip/s 9473 allocs/op
40
- Panko_HasOne_Posts_50 2399 ip/s 473 allocs/op
41
- Panko_Reused_HasOne_Posts_2300 66 ip/s 9419 allocs/op
42
- Panko_Reused_HasOne_Posts_50 2582 ip/s 419 allocs/op
43
-
44
- Panko_Simple_Posts_2300 195 ip/s 2470 allocs/op
45
- Panko_Simple_Posts_50 4838 ip/s 220 allocs/op
46
- Panko_Reused_Simple_Posts_2300 196 ip/s 2416 allocs/op
47
- Panko_Reused_Simple_Posts_50 6241 ip/s 166 allocs/op
48
- ```
data/benchmarks/allocs.rb DELETED
@@ -1,23 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "benchmarking_support"
4
- require_relative "app"
5
- require_relative "setup"
6
-
7
- require "memory_profiler"
8
-
9
- class PostFastSerializer < Panko::Serializer
10
- attributes :id, :body, :title, :author_id
11
- end
12
-
13
- def count_allocs(&)
14
- memory_report = MemoryProfiler.report(&)
15
- puts memory_report.pretty_print
16
- end
17
-
18
- posts = Post.all.to_a
19
- merged_options = {}.merge(each_serializer: PostFastSerializer)
20
- posts_array_serializer = Panko::ArraySerializer.new([], merged_options)
21
-
22
- # prints out 18402
23
- count_allocs { posts_array_serializer.serialize_to_json posts }
data/benchmarks/app.rb DELETED
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "bundler/setup"
4
-
5
- require "active_model"
6
- require "active_record"
7
- require "active_support"
8
- require "active_support/json"
9
-
10
- require "active_model_serializers"
11
- require "panko_serializer"
@@ -1,44 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "benchmark/ips"
4
- require "json"
5
- require "memory_profiler"
6
-
7
- module Benchmark
8
- module Runner
9
- def data
10
- posts = Post.all.includes(:author).to_a
11
- posts_50 = posts.first(50).to_a
12
- posts_single = posts.first(1).to_a
13
- {all: posts, small: posts_50, single: posts_single}
14
- end
15
-
16
- def run(label = nil, time: 10, disable_gc: true, warmup: 3, &block)
17
- fail ArgumentError.new, "block should be passed" unless block
18
-
19
- GC.start
20
-
21
- if disable_gc
22
- GC.disable
23
- else
24
- GC.enable
25
- end
26
-
27
- memory_report = MemoryProfiler.report(&block)
28
-
29
- report = Benchmark.ips(time, warmup, true) do |x|
30
- x.report(label) { yield }
31
- end
32
-
33
- results = {
34
- label: label,
35
- ips: ActiveSupport::NumberHelper.number_to_delimited(report.entries.first.ips.round(2)),
36
- allocs: "#{memory_report.total_allocated}/#{memory_report.total_retained}"
37
- }.to_json
38
-
39
- puts results
40
- end
41
- end
42
-
43
- extend Benchmark::Runner
44
- end
@@ -1,43 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "benchmarking_support"
4
- require_relative "app"
5
- require_relative "setup"
6
-
7
- # disable logging for benchmarks
8
- ActiveModelSerializers.logger = ActiveSupport::TaggedLogging.new(ActiveSupport::Logger.new(File::NULL))
9
-
10
- class AmsAuthorFastSerializer < ActiveModel::Serializer
11
- attributes :id, :name
12
- end
13
-
14
- class AmsPostFastSerializer < ActiveModel::Serializer
15
- attributes :id, :body, :title, :author_id, :created_at
16
- end
17
-
18
- class AmsPostWithHasOneFastSerializer < ActiveModel::Serializer
19
- attributes :id, :body, :title, :author_id
20
-
21
- has_one :author, serializer: AmsAuthorFastSerializer
22
- end
23
-
24
- def benchmark_ams(prefix, serializer, options = {})
25
- merged_options = options.merge(each_serializer: serializer)
26
-
27
- posts = Benchmark.data[:all]
28
-
29
- Benchmark.run("AMS_#{prefix}_Posts_#{posts.count}") do
30
- ActiveModelSerializers::SerializableResource.new(posts, merged_options).to_json
31
- end
32
-
33
- posts_50 = Benchmark.data[:small]
34
-
35
- Benchmark.run("AMS_#{prefix}_Posts_50") do
36
- ActiveModelSerializers::SerializableResource.new(posts_50, merged_options).to_json
37
- end
38
- end
39
-
40
- benchmark_ams "Attributes_Simple", AmsPostFastSerializer
41
- benchmark_ams "Attributes_HasOne", AmsPostWithHasOneFastSerializer
42
- benchmark_ams "Attributes_Except", AmsPostWithHasOneFastSerializer, except: [:title]
43
- benchmark_ams "Attributes_Only", AmsPostWithHasOneFastSerializer, only: [:id, :body, :author_id, :author]
@@ -1,65 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "benchmarking_support"
4
- require_relative "app"
5
-
6
- Benchmark.run("ObjectWriter_OneProperty_PushValue") do
7
- writer = Panko::ObjectWriter.new
8
-
9
- writer.push_object
10
- writer.push_value "value1", "key1"
11
- writer.pop
12
-
13
- writer.output
14
- end
15
-
16
- Benchmark.run("ObjectWriter_TwoProperty_PushValue") do
17
- writer = Panko::ObjectWriter.new
18
-
19
- writer.push_object
20
- writer.push_value "value1", "key1"
21
- writer.push_value "value2", "key2"
22
- writer.pop
23
-
24
- writer.output
25
- end
26
-
27
- Benchmark.run("ObjectWriter_OneProperty_PushValuePushKey") do
28
- writer = Panko::ObjectWriter.new
29
-
30
- writer.push_object
31
- writer.push_key "key1"
32
- writer.push_value "value1"
33
- writer.pop
34
-
35
- writer.output
36
- end
37
-
38
- Benchmark.run("ObjectWriter_TwoProperty_PushValuePushKey") do
39
- writer = Panko::ObjectWriter.new
40
-
41
- writer.push_object
42
- writer.push_key "key1"
43
- writer.push_value "value1"
44
-
45
- writer.push_key "key2"
46
- writer.push_value "value2"
47
- writer.pop
48
-
49
- writer.output
50
- end
51
-
52
- Benchmark.run("ObjectWriter_NestedObject") do
53
- writer = Panko::ObjectWriter.new
54
-
55
- writer.push_object
56
- writer.push_value "value1", "key1"
57
-
58
- writer.push_object "key2"
59
- writer.push_value "value2", "key2"
60
- writer.pop
61
-
62
- writer.pop
63
-
64
- writer.output
65
- end
@@ -1,60 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "benchmarking_support"
4
- require_relative "app"
5
- require_relative "setup"
6
-
7
- class AuthorFastSerializer < Panko::Serializer
8
- attributes :id, :name
9
- end
10
-
11
- class PostFastSerializer < Panko::Serializer
12
- attributes :id, :body, :title, :author_id, :created_at
13
- end
14
-
15
- class PostFastWithJsonSerializer < Panko::Serializer
16
- attributes :id, :body, :title, :author_id, :created_at, :data
17
- end
18
-
19
- class PostFastWithMethodCallSerializer < Panko::Serializer
20
- attributes :id, :body, :title, :author_id, :method_call
21
-
22
- def method_call
23
- object.id * 2
24
- end
25
- end
26
-
27
- class PostWithHasOneFastSerializer < Panko::Serializer
28
- attributes :id, :body, :title, :author_id
29
-
30
- has_one :author, serializer: AuthorFastSerializer
31
- end
32
-
33
- class AuthorWithHasManyFastSerializer < Panko::Serializer
34
- attributes :id, :name
35
-
36
- has_many :posts, serializer: PostFastSerializer
37
- end
38
-
39
- def benchmark(prefix, serializer, options = {})
40
- posts = Benchmark.data[:all]
41
-
42
- merged_options = options.merge(each_serializer: serializer)
43
-
44
- Benchmark.run("Panko_ActiveRecord_#{prefix}_Posts_#{posts.count}") do
45
- Panko::ArraySerializer.new(posts, merged_options).to_json
46
- end
47
-
48
- posts_50 = Benchmark.data[:small]
49
-
50
- Benchmark.run("Panko_ActiveRecord_#{prefix}_Posts_50") do
51
- Panko::ArraySerializer.new(posts_50, merged_options).to_json
52
- end
53
- end
54
-
55
- benchmark "Simple", PostFastSerializer
56
- benchmark "SimpleWithJson", PostFastWithJsonSerializer
57
- benchmark "HasOne", PostWithHasOneFastSerializer
58
- benchmark "SimpleWithMethodCall", PostFastWithMethodCallSerializer
59
- benchmark "Except", PostWithHasOneFastSerializer, except: [:title]
60
- benchmark "Only", PostWithHasOneFastSerializer, only: [:id, :body, :author_id, :author]
@@ -1,46 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "benchmarking_support"
4
- require_relative "app"
5
- require_relative "setup"
6
-
7
- class AuthorFastSerializer < Panko::Serializer
8
- attributes :id, :name
9
- end
10
-
11
- class PostFastSerializer < Panko::Serializer
12
- attributes :id, :body, :title, :author_id
13
- end
14
-
15
- class PostWithHasOneFastSerializer < Panko::Serializer
16
- attributes :id, :body, :title, :author_id
17
-
18
- has_one :author, serializer: AuthorFastSerializer
19
- end
20
-
21
- class AuthorWithHasManyFastSerializer < Panko::Serializer
22
- attributes :id, :name
23
-
24
- has_many :posts, serializer: PostFastSerializer
25
- end
26
-
27
- def benchmark(prefix, serializer, options = {})
28
- posts = Benchmark.data[:all]
29
-
30
- merged_options = options.merge(each_serializer: serializer)
31
-
32
- Benchmark.run("Panko_ActiveRecord_#{prefix}_Posts_#{posts.count}") do
33
- Panko::ArraySerializer.new(posts, merged_options).to_a
34
- end
35
-
36
- posts_50 = Benchmark.data[:small]
37
-
38
- Benchmark.run("Panko_ActiveRecord_#{prefix}_Posts_50") do
39
- Panko::ArraySerializer.new(posts_50, merged_options).to_a
40
- end
41
- end
42
-
43
- benchmark "Simple", PostFastSerializer
44
- benchmark "HasOne", PostWithHasOneFastSerializer
45
- benchmark "Except", PostWithHasOneFastSerializer, except: [:title]
46
- benchmark "Only", PostWithHasOneFastSerializer, only: [:id, :body, :author_id, :author]
@@ -1,99 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "benchmarking_support"
4
- require_relative "app"
5
-
6
- class AuthorFastSerializer < Panko::Serializer
7
- attributes :id, :name
8
- end
9
-
10
- class PostFastSerializer < Panko::Serializer
11
- attributes :id, :body, :title, :author_id, :created_at
12
- end
13
-
14
- class PostFastWithMethodCallSerializer < Panko::Serializer
15
- attributes :id, :body, :title, :author_id, :method_call
16
-
17
- def method_call
18
- object.id * 2
19
- end
20
- end
21
-
22
- class PostWithHasOneFastSerializer < Panko::Serializer
23
- attributes :id, :body, :title, :author_id
24
-
25
- has_one :author, serializer: AuthorFastSerializer
26
- end
27
-
28
- class AuthorWithHasManyFastSerializer < Panko::Serializer
29
- attributes :id, :name
30
-
31
- has_many :posts, serializer: PostFastSerializer
32
- end
33
-
34
- class Post
35
- attr_accessor :id, :body, :title, :created_at, :author_id
36
- attr_reader :author
37
-
38
- def self.create(attrs)
39
- p = Post.new
40
- attrs.each do |k, v|
41
- p.send :"#{k}=", v
42
- end
43
- p
44
- end
45
-
46
- def author=(author)
47
- @author = author
48
- @author_id = author.id
49
- end
50
- end
51
-
52
- class Author
53
- attr_accessor :id, :name
54
-
55
- def self.create(attrs)
56
- a = Author.new
57
- attrs.each do |k, v|
58
- a.send :"#{k}=", v
59
- end
60
- a
61
- end
62
- end
63
-
64
- def benchmark_data
65
- posts = []
66
- ENV.fetch("ITEMS_COUNT", "2300").to_i.times do |i|
67
- posts << Post.create(
68
- id: i,
69
- body: "something about how password restrictions are evil, and less secure, and with the math to prove it.",
70
- title: "Your bank is does not know how to do security",
71
- author: Author.create(id: i, name: "Preston Sego")
72
- )
73
- end
74
-
75
- {all: posts, small: posts.first(50)}
76
- end
77
-
78
- def benchmark(prefix, serializer, options = {})
79
- data = benchmark_data
80
- posts = data[:all]
81
-
82
- merged_options = options.merge(each_serializer: serializer)
83
-
84
- Benchmark.run("Panko_Plain_#{prefix}_Posts_#{posts.count}") do
85
- Panko::ArraySerializer.new(posts, merged_options).to_json
86
- end
87
-
88
- posts_50 = benchmark_data[:small]
89
-
90
- Benchmark.run("Panko_Plain_#{prefix}_Posts_50") do
91
- Panko::ArraySerializer.new(posts_50, merged_options).to_json
92
- end
93
- end
94
-
95
- benchmark "Simple", PostFastSerializer
96
- benchmark "HasOne", PostWithHasOneFastSerializer
97
- benchmark "SimpleWithMethodCall", PostFastWithMethodCallSerializer
98
- benchmark "Except", PostWithHasOneFastSerializer, except: [:title]
99
- benchmark "Only", PostWithHasOneFastSerializer, only: [:id, :body, :author_id, :author]
@@ -1,76 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "benchmarking_support"
4
- require "active_support"
5
-
6
- require "panko_serializer"
7
-
8
- def generate_attributes(count)
9
- (1..count).map { |i| :"attr_#{i}" }
10
- end
11
-
12
- class LeafASerializer < Panko::Serializer
13
- attributes(*generate_attributes(5))
14
- end
15
-
16
- class LeafBSerializer < Panko::Serializer
17
- attributes(*generate_attributes(6))
18
- end
19
-
20
- class ChildrenSerializer < Panko::Serializer
21
- attributes(*generate_attributes(28))
22
-
23
- has_one :leaf_a, serializer: LeafASerializer
24
- has_one :leaf_b, serializer: LeafBSerializer
25
-
26
- def attr_1
27
- end
28
-
29
- def attr_2
30
- end
31
-
32
- def attr_3
33
- end
34
-
35
- def attr_4
36
- end
37
-
38
- def attr_5
39
- end
40
- end
41
-
42
- class ParentSerializer < Panko::Serializer
43
- attributes(*generate_attributes(46))
44
-
45
- has_many :children, serializer: ChildrenSerializer
46
-
47
- def attr_1
48
- end
49
-
50
- def attr_2
51
- end
52
-
53
- def attr_3
54
- end
55
-
56
- def attr_4
57
- end
58
- end
59
-
60
- attrs = generate_attributes(21)
61
- attrs << :children
62
- filters = {
63
- instance: attrs,
64
- children: generate_attributes(11)
65
- }
66
- Benchmark.run("NoFilters") do
67
- Panko::SerializationDescriptor.build(ParentSerializer)
68
- end
69
-
70
- Benchmark.run("Attribute") do
71
- Panko::SerializationDescriptor.build(ParentSerializer, only: [:children])
72
- end
73
-
74
- Benchmark.run("AssociationFilters") do
75
- Panko::SerializationDescriptor.build(ParentSerializer, only: filters)
76
- end
@@ -1,22 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "benchmarking_support"
4
- require_relative "app"
5
-
6
- class NotSerializer
7
- end
8
-
9
- class RealSerializer < Panko::Serializer
10
- end
11
-
12
- Benchmark.run("CantFindConst") do
13
- Panko::SerializerResolver.resolve("cant_find_const", Object)
14
- end
15
-
16
- Benchmark.run("NotSerializer") do
17
- Panko::SerializerResolver.resolve("not", Object)
18
- end
19
-
20
- Benchmark.run("RealSerializer") do
21
- Panko::SerializerResolver.resolve("real", Object)
22
- end
@@ -1,81 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "benchmarking_support"
4
- require_relative "app"
5
- require_relative "setup"
6
-
7
- class PostWithAliasModel < ActiveRecord::Base
8
- self.table_name = "posts"
9
-
10
- alias_attribute :new_id, :id
11
- alias_attribute :new_body, :body
12
- alias_attribute :new_title, :title
13
- alias_attribute :new_author_id, :author_id
14
- alias_attribute :new_created_at, :created_at
15
- end
16
-
17
- class PostWithAliasFastSerializer < Panko::Serializer
18
- attributes :new_id, :new_body, :new_title, :new_author_id, :new_created_at
19
- end
20
-
21
- def benchmark_aliased(prefix, serializer, options = {})
22
- posts = PostWithAliasModel.all.to_a
23
- posts_50 = posts.first(50).to_a
24
-
25
- merged_options = options.merge(each_serializer: serializer)
26
-
27
- Benchmark.run("Panko_#{prefix}_PostWithAliasModels_#{posts.count}") do
28
- Panko::ArraySerializer.new(posts, merged_options).to_json
29
- end
30
-
31
- Benchmark.run("Panko_#{prefix}_Posts_50") do
32
- Panko::ArraySerializer.new(posts_50, merged_options).to_json
33
- end
34
- end
35
-
36
- class AuthorFastSerializer < Panko::Serializer
37
- attributes :id, :name
38
- end
39
-
40
- class PostFastSerializer < Panko::Serializer
41
- attributes :id, :body, :title, :author_id, :created_at
42
- end
43
-
44
- class PostFastWithMethodCallSerializer < Panko::Serializer
45
- attributes :id, :body, :title, :author_id, :created_at, :method_call
46
-
47
- def method_call
48
- object.id
49
- end
50
- end
51
-
52
- class PostWithHasOneFastSerializer < Panko::Serializer
53
- attributes :id, :body, :title, :author_id, :created_at
54
-
55
- has_one :author, serializer: AuthorFastSerializer
56
- end
57
-
58
- class AuthorWithHasManyFastSerializer < Panko::Serializer
59
- attributes :id, :name
60
-
61
- has_many :posts, serializer: PostFastSerializer
62
- end
63
-
64
- def benchmark(prefix, serializer, options = {})
65
- posts = Benchmark.data[:all]
66
-
67
- merged_options = options.merge(each_serializer: serializer)
68
-
69
- Benchmark.run("Panko_#{prefix}_Posts_#{posts.count}") do
70
- Panko::ArraySerializer.new(posts, merged_options).to_a
71
- end
72
-
73
- posts_50 = Benchmark.data[:small]
74
-
75
- Benchmark.run("Panko_#{prefix}_Posts_50") do
76
- Panko::ArraySerializer.new(posts_50, merged_options).to_a
77
- end
78
- end
79
-
80
- benchmark "Simple", PostFastSerializer
81
- benchmark "HasOne", PostWithHasOneFastSerializer