std/benchmark
import std/benchmark to use it. Source: src/std/benchmark.iyi at v0.18.0.
Wall clock only. The other library also prints the CPU time a block took (bm's user, system and total columns) and the bytes it allocated per call (ips's B/op); nothing here reads the process's CPU time, and the collector keeps no lifetime allocation total (std/gc's bytes_since_collection starts again at every collection). Both printed as zeros, whatever the block did: 0.000000 user for a million additions, 0B/op for a block that builds an array. They are not printed now, and Tms and IPS::Entry have no field for them.
Benchmarkclass
pub class Benchmark
module BM
class Job
def execute : Nil
def initialize
def report(label : String = " ", &block : (->)) : Nil
end
class Tms
def initialize(real : Float64, label : String = "")
def label : String
def real : Float64
def to_s(io) : Nil
def to_s : String
end
end
module IPS
class Entry
def action : (->)
def action=(value : (->)) : (->)
def calculate_stats(samples : Array(Float64)) : Nil
def call : Nil
def call_for_100ms : Nil
def cycles : Int32
def cycles=(value : Int32) : Int32
def human_compare : String
def human_iteration_time : String
def human_mean : String
def initialize(label : String, action : (->))
def label : String
def label=(value : String) : String
def mean : Float64
def mean=(value : Float64) : Float64
def ran? : Bool
def relative_stddev : Float64
def relative_stddev=(value : Float64) : Float64
def set_cycles(duration : Std::Time::Span, iterations : UInt64) : Nil
def size : Int32
def size=(value : Int32) : Int32
def slower : Float64
def slower=(value : Float64) : Float64
def stddev : Float64
def stddev=(value : Float64) : Float64
def variance : Float64
def variance=(value : Float64) : Float64
end
class Job
def execute : Nil
def initialize(calculation : Std::Time::Span = Std::Time::Span.seconds(5), warmup : Std::Time::Span = Std::Time::Span.seconds(2), interactive : Bool = false)
def items : Array(Entry)
# Seconds as numbers, as the other library takes them. It asked
# `Time.seconds`, which `Time` (an instant) does not have, so
# `Job.new(1, 1)` did not compile; a length of time is a `Span`. The
# answer is named: a program built from this module's artifact read
# a method with none as one that answers nil.
def self.new(calculation = 5, warmup = 2, interactive = false) : Job
def report(label : String = "", &action : (->)) : Entry
def report : Nil
end
end
def self.bm(& : (BM::Job -> Nil)) : BM::Job
def self.ips(calculation : Std::Time::Span = Std::Time::Span.seconds(5), warmup : Std::Time::Span = Std::Time::Span.seconds(2), interactive : Bool = false, & : (IPS::Job -> Nil)) : IPS::Job
def self.ips(calculation : Int32 = 5, warmup : Int32 = 2, interactive : Bool = false, & : (IPS::Job -> Nil)) : IPS::Job
def self.measure(label : String = "", & : (-> Nil)) : BM::Tms
def self.realtime(& : (-> Nil)) : Std::Time::Span
endSpanalias
pub alias Span = Std::Time::SpanTimealias
pub alias Time = Std::Time::Time
Timing a block: wall-clock ips and bm, built on std/time.