Sha256: 26d792fbb43c00d75b32306918b08cc499d3e49a61f4e579d243b770d3ea1312

Contents?: true

Size: 930 Bytes

Versions: 3

Compression:

Stored size: 930 Bytes

Contents

# frozen_string_literal: true

require "bundler/setup"
Bundler.setup

require "benchmark"
require "benchmark/ips"
require "benchmark/memory"

puts "```ruby"
puts File.read(__FILE__)
puts "```"
puts
puts "### Output"
puts
puts "```"

require_relative "lib/memery"

class Foo
  class << self
    include Memery

    def base_find(char)
      ("a".."k").find { |letter| letter == char }
    end

    memoize def find_z
      base_find("z")
    end

    memoize def find_new(char)
      base_find(char)
    end
  end
end

def test_no_args
  Foo.find_z
end

def test_with_args
  Foo.find_new("d")
end

Benchmark.ips do |x|
  x.report("test_no_args") { test_no_args }
end

Benchmark.memory do |x|
  x.report("test_no_args") { 100.times { test_no_args } }
end

Benchmark.ips do |x|
  x.report("test_with_args") { test_with_args }
end

Benchmark.memory do |x|
  x.report("test_with_args") { 100.times { test_with_args } }
end

puts "```"

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
memery-1.6.0 benchmark.rb
memery-1.5.0 benchmark.rb
memery-1.4.1 benchmark.rb