Sha256: c6c35ea3a1c67e42d3cc7dcb4570f2a2f5e2a4cf48c4dd4ada45a124142bcbee

Contents?: true

Size: 1.13 KB

Versions: 2

Compression:

Stored size: 1.13 KB

Contents

# frozen_string_literal: true

require_relative './benchmarking_support'
require_relative './app'

time = 10
disable_gc = true
ActiveModelSerializers.config.key_transform = :unaltered
has_many_relationships = (0..60).map do |i|
  HasManyRelationship.new(id: i, body: 'ZOMG A HAS MANY RELATIONSHIP')
end
has_one_relationship = HasOneRelationship.new(
  id: 42,
  first_name: 'Joao',
  last_name: 'Moura'
)
primary_resource = PrimaryResource.new(
  id: 1337,
  title: 'New PrimaryResource',
  virtual_attribute: nil,
  body: 'Body',
  has_many_relationships: has_many_relationships,
  has_one_relationship: has_one_relationship
)
serializer = PrimaryResourceSerializer.new(primary_resource)

Benchmark.ams('attributes', time: time, disable_gc: disable_gc) do
  attributes = ActiveModelSerializers::Adapter::Attributes.new(serializer)
  attributes.as_json
end

Benchmark.ams('json_api', time: time, disable_gc: disable_gc) do
  json_api = ActiveModelSerializers::Adapter::JsonApi.new(serializer)
  json_api.as_json
end

Benchmark.ams('json', time: time, disable_gc: disable_gc) do
  json = ActiveModelSerializers::Adapter::Json.new(serializer)
  json.as_json
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
active_model_serializers_custom-0.10.90 test/benchmark/bm_adapter.rb
active_model_serializers-0.10.9 test/benchmark/bm_adapter.rb