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

  local i j time tstart tend
  local shapeList numShapes numIterations
  local min max total avg shape

!callp padR "MYSTR" xxx 10
!say "xxx = ^xxx
!stop
  result shapeList "Sine,Square,Triangle,SawTooth,Pulse,Whitenoise"
  sedit "^shapeList" numShapes "NELEM" ","
 
  res numIterations 10
  
  say "SHAPE        MIN        MAX        AVERAGE"
  say "------------------------------------------"
  loop numShapes j
    sedit "^shapeList" shape "ELEM" j ","
    loop numIterations i
!!!info "Shape ^shape, i ^i, time ^time, min ^min, max ^max" 
      if shape EQS "Whitenoise" then
        ! The X-Midas version of waveform does not have a WHITENOISE waveform
        ! So I will use the WHITENOISE primitive
        timex NOW tstart
        whitenoise/nowarn null SF nels
        timex NOW tend
      else
        timex NOW tstart
        WAVEFORM/nowarn null SF nels ^shape
        timex NOW tend
      endif
      calc/quiet time tend tstart -
      if /debugm GT 0 then 
        info "PERF_WAVEFORM: time = ^time"
      endif
      if i EQ 1 then
        res MIN     time
        res MAX     time
        res TOTAL   time
        res AVG     time
      else
        calc/quiet MIN MIN time MINIMUM
        calc/quiet MAX MAX time MAXIMUM
        calc/quiet TOTAL TOTAL time +
        calc/quiet AVG TOTAL i /
      endif
    endloop
    callp padR shape shapePad
    sedit F:min minForm NFORM (F8.5)
    sedit F:min maxForm NFORM (F8.5)
    sedit F:min avgForm NFORM (F8.5)

    say "^shapePad  ^minForm   ^maxForm   ^avgForm"
  endloop

 
endmacro

procedure padR A:in U:out L:len[10]
  sedit in len "LENGTH"
  res str "^in"
  loop 10-len
    res str "^{str}_"
  endloop
  
  res ^out "^str"
return
