# Performance test, vim: syntax=apl ∇ MAKE_FUT EXPR;F;TXT ⍝ ⍝ ⎕FX a function that executes EXPR CNT times and returns ⍝ the number of milliseconds spent for doing so, and CNT ⍝ TXT← ⊂ 'MS_CNT←FUT CNT;N;Z;MS' TXT←TXT, ⊂ 'N←0 ◊ CNT←5×⌈CNT÷5 ◊ MS←⎕TS' TXT←TXT, ⊂ 'LOOP:' TXT←TXT, ⊂ (0<⍴,EXPR)/'Z←',EXPR TXT←TXT, ⊂ (0<⍴,EXPR)/'Z←',EXPR TXT←TXT, ⊂ (0<⍴,EXPR)/'Z←',EXPR TXT←TXT, ⊂ (0<⍴,EXPR)/'Z←',EXPR TXT←TXT, ⊂ (0<⍴,EXPR)/'Z←',EXPR TXT←TXT, ⊂ '→(CNT>N←N+5)⍴LOOP' TXT←TXT, ⊂ 'MS←1 12 30 24 60 60 1000⊥⎕TS-MS' TXT←TXT, ⊂ 'MS_CNT←MS,CNT' F←⎕FX TXT ∇ ∇ MS_CNT←RUN_PERF EXPR;MS;CNT;N1;N2 ⍝ ⍝ return the total time (in ms) to execute EXPR ⍝ ⍝ 1. create FUT that runs and measures EXPR N times. ⍝ MAKE_FUT EXPR ⍝ ⍝ 2. compute N1 so that FUT N1 takes > 100 ms. ⍝ N1←1 N1←N1×3 ◊ (MS CNT)←FUT N1 ◊ →(MS < 100)⍴⎕LC ⍝ ⍝ 3. compute N2 so that FUT N takes about TPP seconds ⍝ N2←⌈TPP×CNT÷MS ⍝ ⍝ 4. execute FUT N ⍝ MS_CNT←(MS CNT)←FUT N2 'Running ''' (30↑EXPR) ''' ' (8 0⍕CNT) ' times: ' MS 'ms' ∇ ∇T←T0 DELTA EXPR;T2 (MS CNT)←RUN_PERF EXPR ◊ T←MS÷CNT T←T2←0⌈T-T0 ◊ UNIT←' ms' →1+(T2≥1)⍴⎕LC ◊ T2←T2×1000 ◊ UNIT←' μs' →1+(T2≥1)⍴⎕LC ◊ T2←T2×1000 ◊ UNIT←' ns' TOTAL←TOTAL⍪((8 2⍕T2),UNIT) EXPR (8 0⍕CNT) ∇ ∇TOTAL←TPP GO EXPRS;I_1000_1000;I_1000000;R_1000000; T0;T1 ⍝ Arguments for benchmarked functions ⍝ I_100000000 ←? 100000000⍴10 R_100000000 ← I_100000000+.1 I_1000000 ←? 1000000⍴10 R_1000000 ← I_1000000+.1 I_10000 ←? 10000⍴10 R_10000 ← I_10000+.1 I_100 ←? 100⍴10 R_100 ← I_100+.1 TOTAL←1 3⍴' Time ' 'Operation' ' CNT' TOTAL←TOTAL,[1] '-----------' '---------' '--------' T0←0.0 DELTA '' 0⍴T0 DELTA¨EXPRS TOTAL←TOTAL,[1] '-----------' '---------' '--------' ∇ EXPRS← 'I_100000000⋆I_100000000' 'I_100000000⋆R_100000000' EXPRS←EXPRS,'I_1000000⋆I_1000000' 'I_1000000⋆R_1000000' EXPRS←EXPRS,'I_10000⋆I_10000' 'I_10000⋆R_10000' EXPRS←EXPRS,'I_100⋆I_100' 'I_100⋆R_100' T←20000 GO EXPRS T )off