Sus::Fixtures::BenchmarkSourceSusFixturesBenchmarkMeasure

module Measure

Provides a benchmarking measure for a test case.

Definitions

def self.build(parent, description, unique: true, **options, &block)

Builds a new benchmarking measure class for a test case.

Signature

parameter parent Class

The parent test context class.

parameter description String

The description of the measure.

parameter unique Boolean

Whether the measure should have a unique identity.

parameter **options Hash

Options to pass to the Sampler constructor.

parameter block Proc

The block to execute for the measure.

returns Class

The new measure class.

Implementation

def self.build(parent, description, unique: true, **options, &block)
	base = Class.new(parent)
	base.extend(self)
	base.description = description
	base.identity = Identity.nested(parent.identity, base.description, unique: unique)
	base.set_temporary_name("#{self}[#{description}]")
	
	# Store sampler options for later use
	base.define_singleton_method(:sampler_options) {options}
	
	if block_given?
		base.define_method(:run, &block)
	end
	
	return base
end

def leaf?

Returns true if this is a leaf measure.

Signature

returns Boolean

Implementation

def leaf?
	true
end

def print(output)

Prints the measure description to the output.

Signature

parameter output IO

The output stream.

Implementation

def print(output)
	self.superclass.print(output)
	output.write(" measure ", :it, self.description, :reset, " ", :identity, self.identity.to_s, :reset)
end

def to_s

Returns a string representation of the measure.

Signature

returns String

Implementation

def to_s
	"measure #{self.description}"
end

def call(assertions)

Executes the measure within the given assertions context.

Signature

parameter assertions Object

The assertions context.

Implementation

def call(assertions)
	assertions.nested(self, identity: self.identity, isolated: true, measure: true) do |assertions|
		instance = self.new(assertions)
		
		# Create sampler with options
		samples = Sampler.new(**self.sampler_options)
		repeats = Repeats.new(samples)
		
		instance.around do
			instance.run(repeats)
		end
		
		assertions.inform(samples.to_s)
	end
end