! Performance tests for the WAVEFORM primitive.
!
! Author:  Jay Hallam
! Author:  J. Czechowski IV
! Version: $Id: perf_waveform.mm,v 1.3 2006/08/15 23:50:37 jph Exp $
!
startmacro L:nels[1e6]

  invoke shapeList nxm.sys.prim.waveform.ShapeList
  set numIterations 10
  set statTab {}
  
  foreach shape INLIST shapeList
    set statTab.^{shape} {MIN=0,MAX=0,TOTAL=0,AVG=0}
    do i 1 numIterations
      timex NOW tstart
      WAVEFORM OUT=null FORM=SF ELEM=nels SHAPE=^shape
      timex NOW tend
      calc time tend tstart -
      if /debugm then info "^reg.main.name: time = ^time"
      if i EQ 1
        set statTab.^{shape}.MIN     time
        set statTab.^{shape}.MAX     time
        set statTab.^{shape}.TOTAL   time
        set statTab.^{shape}.AVG time
      else
        calc statTab.^{shape}.MIN statTab.^{shape}.MIN time MINIMUM
        calc statTab.^{shape}.MAX statTab.^{shape}.MAX time MAXIMUM
        calc statTab.^{shape}.TOTAL statTab.^{shape}.TOTAL time +
        calc statTab.^{shape}.AVG statTab.^{shape}.TOTAL i /
      endif
!info "Shape ^shape, i ^i, time ^time, tab ^statTab.^{shape}"
    enddo
  endfor

  if /verbosem then
    say "SHAPE        MIN        MAX        AVERAGE"
    say "------------------------------------------"
    foreach key intable statTab
      sedit key shapePad "PADR" 10 "_"
      sedit ^{statTab.^{key}.min} min NFORM "0.000000"
      sedit ^{statTab.^{key}.max} max NFORM "0.000000"
      sedit ^{statTab.^{key}.min} avg NFORM "0.000000"
      say "^shapePad   ^min   ^max   ^avg"
    endfor
  endif
endmacro
