#!/bin/sh # A simple timing test for obstcl \ exec tclsh80 "$0" $@" # Make sure we're loaded. Assume we are in the test directory lappend auto_path [file dirname [pwd]] package require obstcl # catch {delete class Dummy} defclass Dummy { inherit Object option foo constructor {} {} method dummy {} {} variable nothing {} } # Measure time to create a class # catch {delete class Foo} ;# Can't delete classes in obstcl puts "Class definition: [time {defclass ::Foo { inherit ::Object variable foo {} 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 $this 1 2 3 } 10]" } method usescalar {x} { puts "usescalar: [time { set foo $x set 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 # Measure method calls -- "direct" puts "\n\"Direct\" calls through namespace:" puts "empty: [time {namespace eval Foo {empty $foo}} 10]" puts "takeargs: [time {namespace eval Foo {takeargs $foo x y z}} 10]" puts "sum: [time {namespace eval Foo {sum $foo 5 6 7}} 10]"