Permalink
Browse files

+ single speed specs, - GC involvement

  • Loading branch information...
1 parent eda887f commit e807d5c1bd29dbfc4de8a866ecd7f841340ee7c1 @floere committed Nov 19, 2010
Showing with 17 additions and 2 deletions.
  1. +12 −0 spec/lib/phony_spec.rb
  2. +5 −2 spec/spec_helper_extensions.rb
View
@@ -183,16 +183,28 @@
end
describe 'split' do
it 'is fast' do
+ number = @phone_numbers.first
+ performance_of { Phony.split(number) }.should < 0.00005
+ end
+ it 'is fast' do
performance_of { @phone_numbers.each { |number| Phony.split(number) } }.should < 0.00015
end
end
describe 'normalize' do
it 'is fast' do
+ number = @phone_numbers.first
+ performance_of { Phony.normalize(number) }.should < 0.000075
+ end
+ it 'is fast' do
performance_of { @phone_numbers.each { |number| Phony.normalize(number) } }.should < 0.00015
end
end
describe 'formatted' do
it 'is fast' do
+ number = @phone_numbers.first
+ performance_of { Phony.formatted(number) }.should < 0.000075
+ end
+ it 'is fast' do
performance_of { @phone_numbers.each { |number| Phony.formatted(number) } }.should < 0.00015
end
end
@@ -2,9 +2,12 @@ module SpecHelperExtensions
# performance_of { do something here }.should < 0.0001
#
+ require 'benchmark'
def performance_of &block
- require 'benchmark'
- Benchmark.realtime &block
+ GC.disable
+ result = Benchmark.realtime &block
+ GC.enable
+ result
end
# Allows the definition of "describe-wide" examples and describes.

0 comments on commit e807d5c

Please sign in to comment.