require 'strscan' require 'benchmark' line = "2007-09-18 12:28:49 INFO logger (app/controllers/application.rb:88:in `log_processing') - [GET] AuthController.index" COUNTER = 10000 Benchmark.bmbm(10) do |bench| bench.report "strscan" do COUNTER.times do scanner = StringScanner.new(line) timestamp = scanner.scan(/^\d{4}\-\d{2}\-\d{2} \d{2}:\d{2}:\d{2}/) scanner.skip(/\s+/) level = scanner.scan(/\w+/) scanner.skip(/\s+/) logger = scanner.scan(/\w+/) scanner.pos += 1 scanner.skip_until(/\) - /) message = scanner.post_match end end bench.report "regexp" do COUNTER.times do r = Regexp.new('^(\d{4}\-\d{2}\-\d{2} \d{2}:\d{2}:\d{2})\s+(\w+)\s+(\w+)\s+\(.*?\) - (.*)') match_data = r.match(line) timestamp = match_data[1] level = match_data[2] logger = match_data[3] message = match_data[4] end end end