Skip to content

Instantly share code, notes, and snippets.

@araslanov-e
Created December 13, 2013 04:56
Show Gist options
  • Save araslanov-e/7939940 to your computer and use it in GitHub Desktop.
Save araslanov-e/7939940 to your computer and use it in GitHub Desktop.
Тест скорости генерации URL
class EventsHelperTest < ActionView::TestCase
def setup
country = Country.create(name: 'Belarus')
state = State.create(name: 'Minsk')
@event = Event.create(country: country, state: state, name: 'Drinking bear')
end
def test_url_for
n = 10000
Benchmark.bmbm do |x|
x.report('string') { n.times { url_for("/events/#{@event.id}") } }
x.report('helper') { n.times { url_for(event_path(@event)) } }
x.report('hash') { n.times { url_for(controller: 'events', action: 'show', id: @event.id) } }
x.report('polymorphic') { n.times { url_for(@event) } }
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment