Permalink
Browse files

benchmark adjustments

  • Loading branch information...
1 parent fe04a4e commit 74630216c21bc2a654cd0af4edd7eeb46296bdaf Michael Amygdalidis committed Jan 22, 2010
Showing with 20 additions and 7 deletions.
  1. +11 −4 benchmark/benchmark.rb
  2. +2 −0 lib/textquery.rb
  3. +7 −3 lib/textquery/textquery.rb
View
@@ -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 イケヤ")
@@ -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
View
@@ -1,3 +1,5 @@
+# encoding: utf-8
+
$:.unshift(File.dirname(__FILE__) + '/../lib')
require "textquery/textquery.rb"
View
@@ -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]
@@ -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]

0 comments on commit 7463021

Please sign in to comment.