Module: ThreadsafeBenchmark
- Includes:
- Benchmark
- Defined in:
- lib/threadsafe_benchmark.rb
Overview
Overview
The ThreadsafeBenchmark module provides methods for benchmarking Ruby code in a thread-safe manner. Use it as you would the standard Benchmark module.
Defined Under Namespace
Classes: Report
Instance Method Summary collapse
- #threadsafe_benchmark(caption = "", label_width = nil, fmtstr = nil, *labels) ⇒ Object (also: #ts_benchmark)
- #threadsafe_bm(label_width = 0, *labels, &blk) ⇒ Object (also: #ts_bm)
Instance Method Details
#threadsafe_benchmark(caption = "", label_width = nil, fmtstr = nil, *labels) ⇒ Object Also known as: ts_benchmark
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/threadsafe_benchmark.rb', line 28 def threadsafe_benchmark(caption = "", label_width = nil, fmtstr = nil, *labels) Thread.current["io"] = StringIO.new label_width ||= 0 fmtstr ||= Benchmark::FMTSTR raise ArgumentError, "no block" unless iterator? unless Thread.main["caption"] puts caption Thread.main["caption"] = true end results = yield(ThreadsafeBenchmark::Report.new(label_width, fmtstr)) Array === results and results.grep(Tms).each {|t| Thread.current["io"] << (labels.shift || t.label || "").ljust(label_width) Thread.current["io"] << t.format(fmtstr) } puts Thread.current["io"].string end |
#threadsafe_bm(label_width = 0, *labels, &blk) ⇒ Object Also known as: ts_bm
46 47 48 |
# File 'lib/threadsafe_benchmark.rb', line 46 def threadsafe_bm(label_width = 0, *labels, &blk) threadsafe_benchmark(" "*label_width + Benchmark::CAPTION, label_width, Benchmark::FMTSTR, *labels, &blk) end |