Created
November 18, 2014 05:08
-
-
Save mkaschenko/7b21bd968da775626cca to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'benchmark/ips' | |
| @alphabet = Range.new('a', 'z').to_a.join(',') | |
| def slow | |
| @alphabet.gsub(',', '') | |
| end | |
| def fast | |
| @alphabet.delete(',') | |
| end | |
| Benchmark.ips do |x| | |
| x.report('slow') { slow } | |
| x.report('fast') { fast } | |
| x.compare! | |
| end | |
| Calculating ------------------------------------- | |
| slow 9.820k i/100ms | |
| fast 65.006k i/100ms | |
| ------------------------------------------------- | |
| slow 105.372k (± 4.2%) i/s - 530.280k | |
| fast 1.068M (± 5.2%) i/s - 5.330M | |
| Comparison: | |
| fast: 1068256.8 i/s | |
| slow: 105371.9 i/s - 10.14x slower |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment