Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'benchmark'
- require 'paramer'
- class String
- def pad_to(size)
- spaces = size - length
- return self unless spaces > 0
- spaces.times { self << " " }
- self
- end
- end
- def bench(name, options={})
- $stdout.print "#{name} ".pad_to(33)
- $stdout.flush
- result = Benchmark.measure { yield }
- puts "#{result.real} seconds"
- end
- def run(name, string)
- puts name
- bench("- only scanning then injecting:") { string.scan_then_inject }
- bench("- scanning groups and injecting:") { string.scan_groups_then_inject }
- bench("- scanning then splat hashing:") { string.scan_then_splat_hash }
- bench("- splitting then splat hashing:") { string.split_then_splat_hash }
- puts
- end
- TINY = ("foo=bar&this=that&klass=eigen=_method=get&" * 500).freeze
- MED = (TINY * 10).freeze
- LONG = (MED * 10).freeze
- run "Running with tiny string", TINY
- run "Running with medium string", MED
- run "Running with ridiculous string", LONG
Add Comment
Please, Sign In to add comment