puts "========"
puts "OCC25487"
puts "========"
puts ""
##########################################
# Extrema_GenExtPS needs to be optimized
##########################################

cpulimit 1500

pload DATAEXCHANGEKERNEL

# Restore testing shape and get timing characteristics for operation stepread
dchrono perf_h reset
dchrono perf_h start
stepread [locate_data_file OCC25487_LP2.stp] a *
dchrono perf_h stop

# Get elapsed time for operation stepread
set chrono_info [dchrono perf_h show]
regexp {CPU user time: ([-0-9.+eE]+) seconds} $chrono_info full CPU_time
puts "Elapsed time is: $CPU_time"

# Check current OS
set currentOS $tcl_platform(os)

# Check prformance on Windows
if {[string compare $currentOS "Windows NT"] == 0} {
  if {[regexp {Debug mode} [dversion]]} {
    # DEBUG mode
    # initial CPU_time for WINDOWS in DEBUG mode is 1208 ((549+55)*2) sec
    puts "Checking WINDOWS performance in debug mode..."
    if {$CPU_time > 1208.} {
      puts "ERROR: OCC25487 is reproduced."
      puts "       Low performance: $CPU_time (but should be less than 1208 sec)"
    } else {
      puts "Done!"
    }
  } else {
    # OPTIMIZE mode
    # initial CPU_time for WINDOWS in OPTIMIZE mode is 604 (549+55) sec
    puts "Checking WINDOWS performance in optimize mode..."
    if {$CPU_time > 604.} {
      puts "ERROR: OCC25487 is reproduced."
      puts "       Low performance: $CPU_time (but should be less than 604 sec)"
    } else {
      puts "Done!"
    }
  }
}

# Check performance on Linux
if {[string compare $currentOS "Linux"] == 0} {
  if {[regexp {Debug mode} [dversion]]} {
    # DEBUG mode
    # initial CPU_time for LINUX in DEBUG mode is 1500 sec
    puts "Checking LINUX performance in debug mode..."
    if {$CPU_time > 1500.} {
      puts "ERROR: OCC25487 is reproduced."
      puts "       Low performance: $CPU_time (but should be less than 1500 sec)"
    } else {
      puts "Done!"
    }
  } else {
    # OPTIMIZE mode
    # initial CPU_time for LINUX in OPTIMIZE mode is 575 (523+52) sec
    puts "Checking LINUX performance in optimize mode..."
    if {$CPU_time > 575.} {
      puts "ERROR: OCC25487 is reproduced."
      puts "       Low performance: $CPU_time (but should be less than 575 sec)"
    } else {
      puts "Done!"
    }
  }
}
