Raku Land

Gauge

zef:Kaiepi

Build Status

NAME

Gauge - Iterative polling

SYNOPSIS

use v6.d;
use Gauge;
# How fast can (1..10) be generated? Take an estimate of how many iterations
# can be sunk in 1 second every 20 seconds:
.say for Gauge(-> --> Nil { sink 1..10 }).poll(1).throttle(19);

DESCRIPTION

class Gauge is Seq { ... }

Gauge, in general, wraps a lazy, non-deterministic, time-oriented iterator. At its base, it attempts to measure durations of calls to a block with as little overhead as possible in order to avoid unnecessary influence over results. This does not make for a proper benchmark on its own, but may provide raw input for such a utility.

ATTRIBUTES

$!gc

has Bool:D $.gc is default(so $*VM.name eq <moar jvm>.any);

$!gc toggles garbage collection before intensive iterations in general, i.e. those of poll currently. By default, this will be True on MoarVM and the JVM. If set to False, iterations are very likely to be skewed by any interruption due to GC (if available).

METHODS

CALL-ME

method CALL-ME(::?CLASS:_: Block:D $block, *%attrinit --> ::?CLASS:D)

Produces a new Gauge sequence of native uint64 durations of a call to the given block. Measurements of each duration are not monotonic, thus leap seconds and hardware errors will skew results.

If %attrinit is provided, a clone will be produced with it to allow for attributes to be set.

poll

method poll(::?CLASS:D: Real:D $seconds --> ::?CLASS:D)

Returns a new Gauge sequence that produces an Int:D count of iterations of the former totalling a duration of $seconds. This will take longer than the given argument to complete due to the overhead of iteration.

throttle

method throttle(::?CLASS:D: Real:D $seconds --> ::?CLASS:D)

Returns a new Gauge sequence that will sleep $seconds between iterations of the former.

AUTHOR

Ben Davies (Kaiepi)

COPYRIGHT AND LICENSE

Copyright 2022 Ben Davies

This library is free software; you can redistribute it and/or modify it under the Artistic License 2.0.