0
0
Fork 0

changed the benchmark to use different counts of threads

This commit is contained in:
Gibheer 2011-06-09 07:43:03 +02:00
parent e14c7ee9ac
commit e2a4d6584b
1 changed files with 21 additions and 7 deletions

View File

@ -4,6 +4,21 @@ require 'benchmark'
require 'virtus'
require 'polecat'
n = 2500
def run_threads threadcount, count, searcher, query
threads = []
count = count / threadcount
threadcount.times do
threads << Thread.new do
for i in 1..count do
searcher.search query
end
end
end
threads.each {|t| t.join }
end
class Document
include Virtus
@ -26,10 +41,9 @@ writer.write
searcher = Polecat::IndexSearcher.new :reader => writer.create_reader
query = Polecat::Query.new.add(Polecat::Term.new(:name, :lt, 25000))
puts Benchmark.bm { |x|
x.report('search') {
for i in 1..5000 do
searcher.search query
end
}
}
Benchmark.bm do |x|
x.report('1') { run_threads 1, n, searcher, query.dup }
x.report('2') { run_threads 1, n, searcher, query.dup }
x.report('4') { run_threads 1, n, searcher, query.dup }
x.report('8') { run_threads 1, n, searcher, query.dup }
end