Tuesday, December 24, 2013

Ruby: split vs regex, Benchmark

http://stackoverflow.com/questions/7533479/ruby-string-search-which-is-faster-split-or-regex

require 'benchmark'
Benchmark.bm do |x|
    x.report { 50000.times { a = 'a@b.c'.split('@')[0] } }
    x.report { 50000.times { a = 'a@b.c'[/[^@]+/] } }
end

No comments:

Post a Comment

Followers

Blog Archive