tur/perf

stdlib/perf.tur
defn

cached

(cached [p & [cache-size 1024])

cache pattern results within a cycle to avoid redundant evaluation.

ppattern to cache
cache-sizenumber of cache buckets (default: 1024)
Pattern<T> with memoised results for repeated time queries.

  (cached expensive-pat 512)
defn

cached-ttl

(cached-ttl [p cache-size ttl])

cache pattern results with a time-to-live expiry.

ppattern to cache
cache-sizenumber of cache buckets
ttltime-to-live in beats before an entry is re-evaluated

Pattern<T> with TTL-based cache invalidation.

defn

inline-pattern

(inline-pattern [p])

specialise simple patterns for reduced call overhead.

ppattern to inline

An equivalent Pattern<T> with simpler internal structure where possible.

defn

fuse-pattern

(fuse-pattern [p])

fuse consecutive pattern operations to reduce overhead.

ppattern to fuse

Pattern<T> with fused operations where recognised.

defstruct

CompiledPattern

(defstruct CompiledPattern [])

a pattern compiled to native code (conceptual).

defn

compile-pattern

(compile-pattern [p])

attempt to compile a pattern to native code.

ppattern to compile

CompiledPattern or nil if compilation is not supported.

defn

eval-compiled

(eval-compiled [cp time])

evaluate a compiled pattern at a specific time.

cpCompiledPattern
timetime in beats

Pattern value (always 0.0 in this placeholder implementation).

defstruct

LazyPattern<T>

(defstruct LazyPattern<T> [])

pattern whose construction is deferred until first use.

defn

make-lazy-pattern

(make-lazy-pattern [thunk])

create a lazy pattern from a thunk.

thunkfunction that produces the pattern when first evaluated

LazyPattern<T>.

defn

eval-lazy

(eval-lazy [lp time])

evaluate a lazy pattern, constructing it on first use.

lpLazyPattern<T>
timetime in beats

Pattern value.

defn

batch-eval

(batch-eval [p times])

evaluate a pattern at multiple times.

ppattern to evaluate
timesvector of beat times
Vector of pattern values corresponding to each time.

  (batch-eval my-pat [0.0 0.25 0.5 0.75])
defn

batch-eval-process

(batch-eval-process [p times f])

evaluate a pattern at multiple times and transform results.

ppattern to evaluate
timesvector of beat times
ffunction to apply to each result

Vector of processed values.

defn

optimize-pattern

(optimize-pattern [p & [passes [fuse-pattern inline-pattern cached])

apply a list of optimization passes to a pattern.

ppattern to optimize
passeslist of optimization functions (default: fuse, inline, cache)

Optimized Pattern<T>.

defn

optimize

(optimize [p])

apply the standard optimization pipeline.

ppattern to optimize

Optimized Pattern<T>.

defn

optimize-aggressive

(optimize-aggressive [p])

apply an aggressive optimization pipeline including large cache.

ppattern to optimize

Aggressively optimized Pattern<T>.

defn

bench-pattern

(bench-pattern [p iterations & [warmup 10])

measure evaluation throughput for a pattern.

ppattern to benchmark
iterationsnumber of timed iterations
warmupwarmup iterations before timing (default: 10)
Map with :total-ns, :avg-ns, and :iterations.

  (bench-pattern my-pat 10000)
defn

patterns-equal?

(patterns-equal? [p1 p2 times & [tolerance 0.001])

compare two patterns for equality over a set of test times.

p1first pattern
p2second pattern
timesvector of times to test
tolerancefloat tolerance for comparison (default: 0.001)

true if all sample points agree within tolerance.

defn

profile-pattern

(profile-pattern [p])

wrap a pattern to collect timing data on each call.

ppattern to profile

Pattern<T> that accumulates call counts and total nanoseconds.

defn

profile-stats

(profile-stats [profiled-fn])

retrieve profiling statistics from a profiled pattern.

profiled-fnprofiled pattern function from profile-pattern

Map with :calls, :total-time, and :avg-time.

defn

zero-alloc-pattern

(zero-alloc-pattern [computation])

create a pattern guaranteed not to allocate in the hot path.

computationBeats -> T function with no allocations

Pattern<T>.

defn

zero-alloc-cycle

(zero-alloc-cycle [values])

zero-allocation cycling pattern over a pre-allocated vector.

valuespre-allocated vector of values

NumPattern with zero allocation.

defn

zero-alloc-sine

(zero-alloc-sine [freq amp])

zero-allocation sine wave pattern.

freqfrequency in cycles per beat
ampamplitude

NumPattern with zero allocation.

defstruct

PatternPool

(defstruct PatternPool [])

reusable pool of pattern instances.

defn

pool-new

(pool-new [size factory])

create a pattern pool with pre-allocated instances.

sizenumber of instances to pre-allocate
factoryfunction producing a fresh pattern instance

PatternPool.

defn

pool-get

(pool-get [pool])

borrow a pattern from the pool (creates one if pool is empty).

poolPatternPool

Pattern<T>.

defn

pool-return

(pool-return [pool idx])

return a pattern to the pool by index.

poolPatternPool
idxindex of the pattern to return
defn

simd-pattern-4

(simd-pattern-4 [p])

evaluate a pattern at 4 times simultaneously (conceptual).

ppattern to evaluate

Function: vec<Beats> -> vec<T> evaluating all 4 times.

defn

specialize-pattern

(specialize-pattern [p time-range])

constant-fold a pattern over a specific time range.

ppattern to specialise
time-range[start end] pair; if start == end, folds to a constant

Specialised Pattern<T>.

defn

specialize-constant

(specialize-constant [p])

evaluate a pattern once at time 0 and return a constant.

ppattern to specialise

Pattern<T> always returning the value of p at time 0.

defn

track-allocations

(track-allocations [p])

wrap a pattern to track GC allocations per evaluation.

ppattern to track

Pattern<T> that measures allocation delta on each call.