Sha256: 248f246a65199952d8bbd5635ad52dc726a315da0b57dba56dea8c2768c8c298

Contents?: true

Size: 1.35 KB

Versions: 1

Compression:

Stored size: 1.35 KB

Contents

require 'attachment_helper'
require 'benchmark'

AttachmentHelper.attachment_host = 'http://myhost.com'

class Topic
  include AttachmentHelper

  has_attachments [:logo_path, {size: '100x100'}], :pdf_path, :image_paths

  def logo_path
    'uploads/a.png'
  end

  def pdf_path
    'http://hello.com/assets/a.pdf'
  end

  def image_paths
    ['a.png', 'http://other.com/b.png']
  end
end

topic = Topic.new

total_times = 100000
puts "Times: #{total_times}"

Benchmark.bm do |x|
  x.report('Run logo_url') do
    total_times.times do
      topic.logo_url
    end
  end

  x.report('Run logo_url(opts)') do
    total_times.times do
      topic.logo_url(foo: :bar, long: 'this_is_some_long_text')
    end
  end

  x.report('Run logo_filename') do
    total_times.times do
      topic.logo_filename
    end
  end

  x.report('Run pdf_url') do
    total_times.times do
      topic.pdf_url
    end
  end

  x.report('Run pdf_url(opts)') do
    total_times.times do
      topic.pdf_url(foo: :bar, long: 'this_is_some_long_text')
    end
  end

  x.report('Run image_urls') do
    total_times.times do
      topic.image_urls
    end
  end

  x.report('Run image_urls(opts)') do
    total_times.times do
      topic.image_urls(foo: :bar, long: 'this_is_some_long_text')
    end
  end

  x.report('Run image_filenames') do
    total_times.times do
      topic.image_filenames
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
attachment_helper-0.1.0 examples/benchmark.rb