Class: Mxrb::Benchmark

Inherits:
Object
  • Object
show all
Defined in:
lib/mxrb/benchmark.rb

Overview

Repeatable wall-clock benchmark for the main read-only MPR operations.

Instance Method Summary collapse

Constructor Details

#initialize(path, iterations: 3, clock: Process.method(:clock_gettime)) ⇒ Benchmark

Returns a new instance of Benchmark.

Raises:

  • (ArgumentError)


8
9
10
11
12
13
# File 'lib/mxrb/benchmark.rb', line 8

def initialize(path, iterations: 3, clock: Process.method(:clock_gettime))
  @path = File.expand_path(path)
  @iterations = Integer(iterations)
  @clock = clock
  raise ArgumentError, 'iterations must be between 1 and 100' unless (1..100).cover?(@iterations)
end

Instance Method Details

#runObject



15
16
17
18
19
20
# File 'lib/mxrb/benchmark.rb', line 15

def run
  open_time, units = measure { Mxrb.open(@path) { _1.all_units.size } }
  index_time, = measure { Mxrb.open(@path) { _1.semantic_index.artifacts.size } }
  validate_time, = measure { Mxrb.validate(@path).valid? }
  BenchmarkResult.new(@iterations, open_time, index_time, validate_time, units)
end