Kouhei Sutou
kous****@users*****
2006年 11月 28日 (火) 11:01:29 JST
Index: tomoe/benchmark/Makefile.am diff -u /dev/null tomoe/benchmark/Makefile.am:1.1 --- /dev/null Tue Nov 28 11:01:29 2006 +++ tomoe/benchmark/Makefile.am Tue Nov 28 11:01:29 2006 @@ -0,0 +1,12 @@ +# -*- Mode: Makefile; tab-width: 8; indent-tabs-mode: t; -*- + +.PHONY: benchamrk + +benchmark_files = load-dict.rb search-by-recognizer.rb + +benchmark: $(top_builddir)/ext/ruby/tomoe.la + for bench in $(benchmark_files); \ + do \ + echo "running benchmark: $$bench"; \ + $(RUBY) $$bench; \ + done Index: tomoe/benchmark/load-dict.rb diff -u /dev/null tomoe/benchmark/load-dict.rb:1.1 --- /dev/null Tue Nov 28 11:01:29 2006 +++ tomoe/benchmark/load-dict.rb Tue Nov 28 11:01:29 2006 @@ -0,0 +1,20 @@ +require "benchmark" + +benchmark_dir = File.expand_path(File.dirname(__FILE__)) +top_dir = File.expand_path(File.join(benchmark_dir, "..")) +test_dir = File.join(top_dir, "test") +$LOAD_PATH.unshift(File.join(top_dir, "ext", "ruby", ".libs")) +$LOAD_PATH.unshift(File.join(top_dir, "ext", "ruby")) +$LOAD_PATH.unshift(File.join(test_dir)) + +require "tomoe-spec-utils" + +n = 10 +Benchmark.bmbm do |x| + TomoeSpecUtils::Config.dictionaries.sort.each do |dictionary| + x.report(File.basename(dictionary)) do + n.times {Tomoe::Dict.new(dictionary, false)} + end + GC.start + end +end Index: tomoe/benchmark/search-by-recognizer.rb diff -u /dev/null tomoe/benchmark/search-by-recognizer.rb:1.1 --- /dev/null Tue Nov 28 11:01:29 2006 +++ tomoe/benchmark/search-by-recognizer.rb Tue Nov 28 11:01:29 2006 @@ -0,0 +1,35 @@ +require "benchmark" +require 'tempfile' + +benchmark_dir = File.expand_path(File.dirname(__FILE__)) +top_dir = File.expand_path(File.join(benchmark_dir, "..")) +test_dir = File.join(top_dir, "test") +$LOAD_PATH.unshift(File.join(top_dir, "ext", "ruby", ".libs")) +$LOAD_PATH.unshift(File.join(top_dir, "ext", "ruby")) +$LOAD_PATH.unshift(File.join(test_dir)) + +require 'tomoe-spec-utils' + +context = Tomoe::Context.new +config_file = TomoeSpecUtils::Config.make_config_file +context.load_config(config_file.path) +context.load_recognizer(TomoeSpecUtils::Config.recognizer_dir, "simple") + +n = 10 +Benchmark.bmbm do |x| + TomoeSpecUtils::Config.test_data_files.sort.each do |file| + expected, writing = TomoeSpecUtils::TestData.parse(file) + query = Tomoe::Query.new + query.writing = writing + base = File.basename(file) + x.report(base) do + failed = false + n.times do + actual = context.search(query).collect {|cand| cand.character.utf8} + failed = true if actual != expected + end + p "search result doesn't match #{base}" if failed + end + GC.start + end +end