module

Mica::Testing::Complexity

Proves a workload linear by its operation count (from a Core::WorkMeter), never by wall time, so the result is the same on a loaded machine.

The workload runs at size and at factor times size. A linear workload's operations grow by about factor; a quadratic one's by factor squared. The bound allows slack for fixed costs and for n log n steps (sorting).

result = Mica::Testing::Complexity.measure("many attributes", 2_000) do |n|
  xml = "<a " + (1..n).join(' ') { |i| %(a#{i}="1") } + "/>"
  Mica::XML.parse(xml).parse_operations
end
result.linear? # => true

Constants

FACTOR = 4

Default multiplier between the two sizes.

SLACK = 1.25

Default allowance over a perfectly linear ratio.

Class methods

measure(name : String, size : Int32, factor : Int32 = FACTOR, slack : Float64 = SLACK, & : Int32 -> Int64) : Result

Runs the block at size and size * factor and returns both operation counts. The block builds its input for the given size, runs the workload and returns the operations it charged.

Source

Nested types