Version 2 of Performance difference tcl 8.5 vs 8.6

Updated 2016-12-13 23:11:47 by bll

wiwo 2016-12-13

Why is tcl 8.5 much faster than 8.6 with this script:

github mandel.tcl

#!/usr/bin/tclsh

# Optimized Version by Samuel Zafrany
# Ported from C by Anders Bergh <[email protected]>

set BAILOUT 16
set MAX_ITERATIONS 1000

proc mandelbrot {x y} {
       global BAILOUT
       global MAX_ITERATIONS

       set cr [expr {$y - 0.5}]
       set ci $x
       set zi 0.0
       set zr 0.0
       set i 0

       while {1} {
               incr i
               set temp [expr {$zr * $zi}]
               set zr2 [expr {$zr * $zr}]
               set zi2 [expr {$zi * $zi}]
               set zr [expr {$zr2 - $zi2 + $cr}]
               set zi [expr {$temp + $temp + $ci}]

               if {$zi2 + $zr2 > $BAILOUT} {
                       return $i
               }

               if {$i > $MAX_ITERATIONS} {
                       return 0
               }
       }
}

set begin [clock clicks -milliseconds]

for {set y -39} {$y < 39} {incr y} {
       puts ""
       for {set x -39} {$x < 39} {incr x} {
               set i [mandelbrot [expr {$x / 40.0}] [expr {$y / 40.0}]]

               if {$i == 0} {
                       puts -nonewline "*"
               } else {
                       puts -nonewline " "
               }
               flush stdout
       }
}
puts ""

set diff [expr [clock clicks -milliseconds] - $begin]
#puts "Tcl Elapsed [expr int($diff / 1000)] seconds ($diff ms)"
puts "Tcl Elapsed [expr int($diff / 1000)]"

8.5: Tcl Elapsed 1.08

8.6: Tcl Elapsed 1.463

This might be worth investigating.

bll 2016-12-13 Put the main loop into a procedure, comment out all the puts and flush and use "puts time main 10" to time it:

bll-tecra:bll$ tclsh8.6 t.tcl
2379487.4 microseconds per iteration
bll-tecra:bll$ tclsh8.5 t.tcl
2028435.5 microseconds per iteration

So yes, it does seem a bit slower.