[Groonga-commit] droonga/fluent-plugin-droonga at 553b3b9 [master] Define ScanBenchmark as a class

Back to archive index

YUKI Hiroshi null+****@clear*****
Fri Oct 25 17:59:42 JST 2013


YUKI Hiroshi	2013-10-25 17:59:42 +0900 (Fri, 25 Oct 2013)

  New Revision: 553b3b961fd104ef4f87b843747b53aa294d95e6
  https://github.com/droonga/fluent-plugin-droonga/commit/553b3b961fd104ef4f87b843747b53aa294d95e6

  Message:
    Define ScanBenchmark as a class

  Modified files:
    benchmark/watch/benchmark-scan.rb

  Modified: benchmark/watch/benchmark-scan.rb (+33 -14)
===================================================================
--- benchmark/watch/benchmark-scan.rb    2013-10-25 17:29:47 +0900 (aaee923)
+++ benchmark/watch/benchmark-scan.rb    2013-10-25 17:59:42 +0900 (668d1b5)
@@ -29,25 +29,44 @@ class StubWorker
   end
 end
 
+class ScanBenchmark
+  def initialize(n_times)
+    @n_times = n_times
+    setup
+  end
 
-database_path = "/tmp/watch-benchmark"
-ddl_path = File.expand_path(File.join(__FILE__, "..", "benchmark-watch-ddl.grn"))
-FileUtils.rm_rf(database_path)
-FileUtils.mkdir_p(database_path)
-`cat #{ddl_path} | groonga -n #{database_path}/db`
+  def setup
+    setup_database
+    @context = Groonga::Context.new
+    @context.open_database("#{@database_path}/db")
+    @worker = StubWorker.new(@context)
+    @watch = Droonga::WatchHandler.new(@worker)
+    @hits = []
+  end
 
-Groonga::Database.open("#{database_path}/db")
+  def setup_database
+    @database_path = "/tmp/watch-benchmark"
+    @ddl_path = File.expand_path(File.join(__FILE__, "..", "benchmark-watch-ddl.grn"))
+    FileUtils.rm_rf(@database_path)
+    FileUtils.mkdir_p(@database_path)
+    `cat #{@ddl_path} | groonga -n #{@database_path}/db`
+  end
 
-worker = StubWorker.new(Groonga::Context.default)
-watch = Droonga::WatchHandler.new(worker)
+  def run
+    @n_times.times do
+      scan("This is a comment.")
+    end
+  end
+
+  def scan(target)
+    @watch.send(:scan_body, @hits, target)
+    @hits.clear
+  end
+end
 
-n = 100
 Benchmark.bmbm do |benchmark|
+  scan_benchmark = ScanBenchmark.new(100)
   benchmark.report("TODO: LABEL") do
-    hits = []
-    n.times do
-      watch.send(:scan_body, hits, "This is a comment.")
-      hits.clear
-    end
+    scan_benchmark.run
   end
 end
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index