#!/bin/sh
# A simple timing test for tcl++ in Tcl8.0 \
	exec tclsh8.0 "$0" $@"

# Make sure we're loaded
package require tcl++
catch {delete class Dummy}
class Dummy {
    constructor {} {}
    method dummy {} {}
    protected variable nothing {}
}

# Measure time to create a class. To be fair, the second
# time (if you source this file from tclsh8.0) is somewhat
# faster.
catch {delete class Foo}
puts "Class definition: [time {class Foo {
    protected variable foo {}
    protected variable bar

    method empty {} {
	;
    }
    method takeargs {x y z} {
	;
    }
    method sum {x y z} {
	expr {$x + $y + $z}
    }
    method callself {} {
	puts "self-call: [time {
	    sum 1 2 3
	} 10]"
    }
    method usescalar {x} {
	puts "usescalar: [time {
	    set v(foo) $x
	    set v(foo)
	} 10]"
    }
    method usearray {x} {
	puts "usearray:  [time {
	    set bar($x) $x
	    set bar($x)
	} 10]"
    }
}}]"

# Measure time to create an object
set unique 0
puts "Create an object: [time {set foo [Foo foo[incr unique]]} 10]"

# Measure method calls
puts "empty:     [time {$foo empty} 10]"
puts "takeargs:  [time {$foo takeargs x y z} 10]"
puts "sum:       [time {$foo sum 5 6 7} 10]"
$foo callself
$foo usescalar q
$foo usearray q