diff options
| author | sebres <sebres@users.sourceforge.net> | 2025-01-22 17:23:14 (GMT) |
|---|---|---|
| committer | sebres <sebres@users.sourceforge.net> | 2025-01-22 17:23:14 (GMT) |
| commit | 733cb169900d1d47d01112f774e66d11fd8ba5f2 (patch) | |
| tree | b535fadf1112b8ff936e9f872c8ff86fb9fbbb87 | |
| parent | e76fe7a1c724d16be8d67aedf48df033a12aca8c (diff) | |
| download | tcl-733cb169900d1d47d01112f774e66d11fd8ba5f2.zip tcl-733cb169900d1d47d01112f774e66d11fd8ba5f2.tar.gz tcl-733cb169900d1d47d01112f774e66d11fd8ba5f2.tar.bz2 | |
timerate: added test illustrating drastic growth of execution time on iteration with quadratic complexity
| -rw-r--r-- | tests/cmdMZ.test | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/tests/cmdMZ.test b/tests/cmdMZ.test index 028a71b..d9f4282 100644 --- a/tests/cmdMZ.test +++ b/tests/cmdMZ.test @@ -487,7 +487,26 @@ test cmdMZ-6.12 {Tcl_TimeRateObjCmd: done optimization: nested call of self insi } list [lindex [timerate $m1 1000 5] 2] $x } {5 20} - +test cmdMZ-6.13 {Tcl_TimeRateObjCmd: stability by O(n**2), avoid long execution time on growing iteration time} { + set result {} + # test the function with quadratic complexity (iteration growth 2x, 10x, 100x): + foreach e {2 10 100} { + set x 1 + set m1 [timerate { + apply {x { + while {[incr x -1]} {} + }} [set x [expr {$x*$e}]] + } 50] + lappend result "${e}x" + # check it was too slow (it is OK to use factor 2 to prevent sporadic + # errors on some slow systems or time issues, because if it is not fixed, + # the execution time may grow hundreds and thousand times): + if {[lindex $m1 6] > 50 * 2} { + lappend result "unexpected long: $m1" + } + } + set result +} {2x 10x 100x} # The tests for Tcl_WhileObjCmd are in while.test # cleanup |
