Created
March 5, 2013 09:18
-
-
Save iorionda/5089005 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
| # -*- coding:utf-8 -*- | |
| require 'benchmark' | |
| def gsub_check | |
| 10000.times do |n| | |
| " ".gsub(/ /, " ") | |
| end | |
| end | |
| def gsub_check_2 | |
| 10000.times do |n| | |
| " ".gsub!(/ /, " ") | |
| end | |
| end | |
| def tr_check | |
| 10000.times do |n| | |
| " ".tr(" ", " ") | |
| end | |
| end | |
| Benchmark.bm(100) do |x| | |
| x.report("gsub") { gsub_check } | |
| x.report("gsub!") { gsub_check_2 } | |
| x.report("tr") { tr_check } | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment