Sha256: 0a6f205cdd6880dfd8308b5cfe6bba10d038e7fb0e7d0cc1c6db452c104d72ca
Contents?: true
Size: 1.81 KB
Versions: 14
Compression:
Stored size: 1.81 KB
Contents
# frozen_string_literal: true require_relative "./benchmarking_support" require_relative "./app" require_relative "./setup" # disable logging for benchmarks ActiveModelSerializers.logger = ActiveSupport::TaggedLogging.new(ActiveSupport::Logger.new('/dev/null')) class AmsAuthorFastSerializer < ActiveModel::Serializer attributes :id, :name end class AmsPostFastSerializer < ActiveModel::Serializer attributes :id, :body, :title, :author_id, :created_at end class AmsPostWithHasOneFastSerializer < ActiveModel::Serializer attributes :id, :body, :title, :author_id has_one :author, serializer: AmsAuthorFastSerializer end def benchmark_ams(prefix, serializer, options = {}) merged_options = options.merge(each_serializer: serializer) data = Benchmark.data posts = data[:all] posts_50 = data[:small] Benchmark.run("AMS_#{prefix}_Posts_#{posts.count}") do ActiveModelSerializers::SerializableResource.new(posts, merged_options).to_json end data = Benchmark.data posts = data[:all] posts_50 = data[:small] Benchmark.run("AMS_#{prefix}_Posts_50") do ActiveModelSerializers::SerializableResource.new(posts_50, merged_options).to_json end end benchmark_ams "Attributes_Simple", AmsPostFastSerializer benchmark_ams "Attributes_HasOne", AmsPostWithHasOneFastSerializer benchmark_ams "Attributes_Except", AmsPostWithHasOneFastSerializer, except: [:title] benchmark_ams "Attributes_Only", AmsPostWithHasOneFastSerializer, only: [:id, :body, :author_id, :author] ActiveModel::Serializer.config.adapter = :json_api benchmark_ams "JsonAPI_Simple", AmsPostFastSerializer benchmark_ams "JsonAPI_HasOne", AmsPostWithHasOneFastSerializer benchmark_ams "JsonAPI_Except", AmsPostWithHasOneFastSerializer, except: [:title] benchmark_ams "JsonAPI_Only", AmsPostWithHasOneFastSerializer, only: [:id, :body, :author_id, :author]
Version data entries
14 entries across 14 versions & 1 rubygems