]> gitweb.factorcode.org Git - factor.git/blob - extra/tensors/benchmark/benchmark.factor
Switch to https urls
[factor.git] / extra / tensors / benchmark / benchmark.factor
1 ! Copyright (C) 2019 HMC Clinic.
2 ! See https://factorcode.org/license.txt for BSD license.
3 USING: arrays kernel locals math math.functions math.statistics memory
4 sequences tools.time ;
5 IN: tensors.benchmark
6
7 ! puts items from els (a quotation) on stack, runs ops (a quot w no stack effect) n times
8 ! returns an array with times (ns) for each trial
9 :: benchmark-multiple ( els: ( -- .. ) op: ( .. -- .. ) n -- ..arr )
10     ! put els on stack
11     els call
12     ! create array
13     n 0 <array> :> arr
14     ! perform op n times
15     n [ gc [ op benchmark ] dip arr set-nth ] each-integer
16     arr ; inline
17
18
19 ! finds the confidence interval of seq with significance level 95
20 :: confidence-interval ( seq -- {c1,c2} )
21     seq mean :> m
22     ! HARDCODING ALERT: z value for alpha = 95 is 1.96
23     seq sample-std 1.96 *
24     ! div by sqrt(n)
25     seq length sqrt / :> modifier
26     m modifier -
27     m modifier +
28     2array ;