Sha256: ff7c15a7ccc9b1a7aed7deb191b443c76d7afc7ee1c301f367d8f7a4e758bbee

Contents?: true

Size: 1.42 KB

Versions: 9

Compression:

Stored size: 1.42 KB

Contents

# frozen_string_literal: true
require_relative "./benchmarking_support"
require_relative "./app"
require_relative "./setup"

class AuthorFastSerializer < Panko::Serializer
  attributes :id, :name
end


class PostFastSerializer < Panko::Serializer
  attributes :id, :body, :title, :author_id, :created_at
end

class PostFastWithMethodCallSerializer < Panko::Serializer
  attributes :id, :body, :title, :author_id, :created_at, :method_call

  def method_call
    object.id
  end
end

class PostWithHasOneFastSerializer < Panko::Serializer
  attributes :id, :body, :title, :author_id, :created_at

  has_one :author, serializer: AuthorFastSerializer
end

class AuthorWithHasManyFastSerializer < Panko::Serializer
  attributes :id, :name

  has_many :posts, serializer: PostFastSerializer
end


def benchmark(prefix, serializer, options = {})
  data = Benchmark.data
  posts = data[:all]
  posts_50 = data[:small]

  merged_options = options.merge(each_serializer: serializer)

  Benchmark.run("Panko_#{prefix}_Posts_#{posts.count}") do
    Panko::ArraySerializer.new(posts, merged_options).to_json
  end

  data = Benchmark.data
  posts = data[:all]
  posts_50 = data[:small]

  Benchmark.run("Panko_#{prefix}_Posts_50") do
    Panko::ArraySerializer.new(posts_50, merged_options).to_json
  end
end




benchmark 'SimpleWithMethodCall', PostFastWithMethodCallSerializer
benchmark "HasOne", PostWithHasOneFastSerializer
benchmark "Simple", PostFastSerializer

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
panko_serializer-0.3.3 benchmarks/sanity.rb
panko_serializer-0.3.2 benchmarks/sanity.rb
panko_serializer-0.2.2 benchmarks/sanity.rb
panko_serializer-0.2.1 benchmarks/sanity.rb
panko_serializer-0.2.0 benchmarks/sanity.rb
panko_serializer-0.1.10 benchmarks/sanity.rb
panko_serializer-0.1.9 benchmarks/sanity.rb
panko_serializer-0.1.8 benchmarks/sanity.rb
panko_serializer-0.1.7 benchmarks/sanity.rb