Sha256: 05a5cc46630c68448e9d7759f07e9d013e68f8eba437eb28a556a19f85a35107

Contents?: true

Size: 1.57 KB

Versions: 23

Compression:

Stored size: 1.57 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, :method_call

  def method_call
    object.id * 2
  end
end

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

  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_ActiveRecord_#{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_ActiveRecord_#{prefix}_Posts_50") do
    Panko::ArraySerializer.new(posts_50, merged_options).to_json
  end
end

benchmark "Simple", PostFastSerializer
benchmark "HasOne", PostWithHasOneFastSerializer
benchmark "SimpleWithMethodCall", PostFastWithMethodCallSerializer
benchmark "Except", PostWithHasOneFastSerializer, except: [:title]
benchmark "Only", PostWithHasOneFastSerializer, only: [:id, :body, :author_id, :author]

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
panko_serializer-0.7.2 benchmarks/bm_panko_json.rb
panko_serializer-0.7.1 benchmarks/bm_panko_json.rb
panko_serializer-0.7.0 benchmarks/bm_panko_json.rb
panko_serializer-0.6.0 benchmarks/bm_panko_json.rb
panko_serializer-0.5.10 benchmarks/bm_panko_json.rb
panko_serializer-0.5.9 benchmarks/bm_panko_json.rb
panko_serializer-0.5.8 benchmarks/bm_panko_json.rb
panko_serializer-0.5.7 benchmarks/bm_panko_json.rb
panko_serializer-0.5.6 benchmarks/bm_panko_json.rb
panko_serializer-0.5.5 benchmarks/bm_panko_json.rb
panko_serializer-0.5.4 benchmarks/bm_panko_json.rb
panko_serializer-0.5.3 benchmarks/bm_panko_json.rb
panko_serializer-0.5.2 benchmarks/bm_panko_json.rb
panko_serializer-0.5.1 benchmarks/bm_panko_json.rb
panko_serializer-0.5.0 benchmarks/bm_panko_json.rb
panko_serializer-0.4.4 benchmarks/bm_panko_json.rb
panko_serializer-0.4.3 benchmarks/bm_panko_json.rb
panko_serializer-0.4.2 benchmarks/bm_panko_json.rb
panko_serializer-0.4.0 benchmarks/bm_panko_json.rb
panko_serializer-0.3.9 benchmarks/bm_panko_json.rb