Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- str = "abcdefghijklmnopqrstuvwxyz"
- 1.upto(10){|x|
- str << str
- }
- t1 = Time.now.to_f
- 1.upto(1000000){|x|
- str =~ /jkl/
- }
- t2 = Time.now.to_f
- reg = /jkl/
- puts "Time: #{t2 - t1}"
- 1.upto(1000000){|x|
- str =~ reg
- }
- t3 = Time.now.to_f
- puts "Time: #{t3 - t2}"
- #Output follows from repeated program runs...
- @hybrid:~/Documents$ ruby regex_bench.rb
- Time: 4.46183609962463
- Time: 5.01269507408142
- @hybrid:~/Documents$ ruby regex_bench.rb
- Time: 4.91851782798767
- Time: 5.75694799423218
Add Comment
Please, Sign In to add comment