Version 3 of Performance difference tcl 8.5 vs 8.6

Updated 2016-12-15 06:53:49 by wiwo

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]

proc do {} {
        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 ""
}
do

set diff [expr [clock clicks -milliseconds] - $begin]
puts "Tcl Elapsed [expr $diff / 1000.0]"

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.

wiwo 2016-12-15 I pasted the wrong version of the script. This is now fixed. The timings are from the new and correct version above. Tcl 8.6 is constantly 30 to 35 % slower than 8.5.