⍝ Timing test script for [put]:
⍝
⍝     test 'put'            ⍝ performance timing test.
⍝   1 test 'put'            ⍝ performance timing test (show progress).
⍝
⍝      Set [loops] and [rows] to suit your machine:

    getenv←{⍎⊃(0=⎕nc ⍵)↓ ⍵ '⍺'}                 ⍝ get environment variable.

    loops ← 1000 getenv 'loops'                 ⍝ default 1000 loops.
    rows  ← 1000 getenv 'rows'                  ⍝ default 1000-row table.
    nest  ←    0 getenv 'nest'                  ⍝ default simple fields.

    +ddb.remove'ddb test'                       ⍝ ensure file removed.
0
    chars←'chars'  80, 10 × 1-2×nest            ⍝ char vectors
    ints←'ints'   323                           ⍝ intg scalars
    doubs←'doubs' 645, 2 4 × 1-2×nest           ⍝ doub matrices

    tab←'ddb test' ddb.create chars ints doubs  ⍝ create table.

    enclose←{nest:⊂[1↓⍳⍴⍴⍵]⍵ ⋄ ⍵}               ⍝ enclose if nested.

    cvals←enclose rows 10⍴⎕a                    ⍝ char vector values.
    ivals←     ⍳rows                            ⍝ intg scalar values.
    dvals←enclose rows 2 4⍴*1                   ⍝ doub matrix values.

    vals←cvals ivals dvals                      ⍝ values for all fields.

    {}tab ddb.append vals                       ⍝ append some values.

    put←{                                       ⍝ replace all fields.
        mask←(rows|⍵)>⍳rows                     ⍝ mask for first ⍵ rows.
        puts←mask∘⌿¨vals                        ⍝ first ⍵ rows.
        tab ddb.put mask tab.names puts         ⍝ replace first ⍵ rows.
    }

    {}⎕wa                                       ⍝ compact for consistent test.

    {} {0}∘put¨time ⍳loops                      ⍝ put timing test.
        
    +ddb.remove tab                             ⍝ remove table.
1
⍝   
⍝   Back to: Contents