Sha256: 5cc74878104ae34c97f883d8b2abf76e4c1ccd939e928a49d614272a89fdc71c

Contents?: true

Size: 525 Bytes

Versions: 3

Compression:

Stored size: 525 Bytes

Contents

require "benchmark/ips"
require "attr_extras"
require "takes_macro"

class A
  pattr_initialize :a, [:b!, :c]
end

TakesMacro.monkey_patch_object

class B
  takes :a, [:b!, :c]
end

class C
  def initialize(a, b:, c: nil)
    @a = a
    @b = b
    @c = c
  end

  private

  attr_reader :a, :b, :c
end

Benchmark.ips do |x|
  x.report("attr_extras") do
    A.new(:a, b: :b)
  end

  x.report("takes_macro") do
    B.new(:a, b: :b)
  end

  x.report("hand written initializer") do
    C.new(:a, b: :b)
  end

  x.compare!
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
takes_macro-1.0.1 benchmarks/takes_macro_vs_attr_extras.rb
takes_macro-1.0.0 benchmarks/takes_macro_vs_attr_extras.rb
takes_macro-0.1.0 benchmarks/takes_macro_vs_attr_extras.rb