###############################################################################
#
# perf.eagle --
#
# Extensible Adaptable Generalized Logic Engine (Eagle)
#
# Copyright (c) 2007-2012 by Joe Mistachkin.  All rights reserved.
#
# See the file "license.terms" for information on usage and redistribution of
# this file, and for a DISCLAIMER OF ALL WARRANTIES.
#
# RCS: @(#) $Id: $
#
###############################################################################

source [file join [file normalize [file dirname [info script]]] prologue.eagle]

###############################################################################

if {![info exists iterations]} then {
  set iterations 9500

  #
  # NOTE: Adjust the expected performance number based on the
  #       relative performance of this machine, if available.
  #
  if {![info exists no(relativePerformance)]} then {
    if {[llength [info commands calculateRelativePerformance]] > 0} then {
      set iterations [calculateRelativePerformance iterations $iterations]
      set iterations [expr {round($iterations)}]
    }
  }
}

###############################################################################

runTest {test perf-1.1 {isolated variable increments per second} -body {
  set x [string trim [lindex [split [execTestShell \
      [list -eventflags Wait -success Success] \
      -eval [appendArgs \" {after flags =Immediate; \
      catch {after 1000 [list interp cancel]; set x 0; \
      while {1} {incr x}}; puts stdout $x} \"]] \n] end-1]]

  waitForProcesses [list [info previouspid]] 5000

  tputs $test_channel [appendArgs "---- expected iterations: " $iterations \n]
  tputs $test_channel [appendArgs "---- actual iterations: " $x \n]

  set x
} -cleanup {
  catch {info previouspid true}
} -constraints {eagle shell testExec performance tip285} -match expression \
-result {$x >= $iterations}}

###############################################################################

unset -nocomplain x iterations

###############################################################################

source [file join [file normalize [file dirname [info script]]] epilogue.eagle]
