Skip to content

Commit

Permalink
benchmark adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Amygdalidis committed Jan 22, 2010
1 parent fe04a4e commit 7463021
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
15 changes: 11 additions & 4 deletions benchmark/benchmark.rb
@@ -1,5 +1,10 @@
# encoding: utf-8

require 'rubygems'
require 'benchmark'
require 'lib/textquery.rb'
#require 'unprof'
require './lib/textquery.rb'


queries = []
queries << TextQuery.new("イケア OR イケヤ")
Expand All @@ -10,11 +15,13 @@
text << s
}

n = 500000
n = 1000
Benchmark.bm do |x|
x.report do
queries.each do |q|
q.match?(text)
n.times do
queries.each do |q|
q.match?(text)
end
end
end
end
2 changes: 2 additions & 0 deletions lib/textquery.rb
@@ -1,3 +1,5 @@
# encoding: utf-8

$:.unshift(File.dirname(__FILE__) + '/../lib')

require "textquery/textquery.rb"
10 changes: 7 additions & 3 deletions lib/textquery/textquery.rb
Expand Up @@ -7,14 +7,18 @@
$KCODE = 'u'
end


BLAH = Regexp.new("(\d)*(~)?([^~]+)(~)?(\d)*$")


class WordMatch < Treetop::Runtime::SyntaxNode

@@regex ||= {}
@@regex_case ||= {}

def eval(text, opt)

fuzzy = query.match(/(\d)*(~)?([^~]+)(~)?(\d)*$/)
fuzzy = query.match(BLAH)

q = []
q.push "." if fuzzy[2]
Expand All @@ -27,8 +31,8 @@ def eval(text, opt)
regex = "^#{q}#{opt[:delim]}|#{opt[:delim]}#{q}#{opt[:delim]}|#{opt[:delim]}#{q}$|^#{q}$"

unless @@regex[regex] then
@@regex[regex] = Regexp.new(regex, Regexp::IGNORECASE, 'utf8')
@@regex_case[regex] = Regexp.new(regex, nil, 'utf8')
@@regex[regex] = Regexp.new(regex, Regexp::IGNORECASE)
@@regex_case[regex] = Regexp.new(regex, nil)
end

if opt[:ignorecase]
Expand Down

0 comments on commit 7463021

Please sign in to comment.