View · Search · Index
No registered users in community xowiki
in last 10 minutes

[Xotcl] Re: performance

From: Gustaf Neumann <Gustaf.Neumann_at_wu-wien.ac.at>
Date: Tue, 13 Feb 2001 16:02:24 +0100 (CET)

>>>>> "KL" == Kristoffer Lawson <setok_at_fishpool.com> writes:
KL> Just for interest I implemented one of the OO tests from Doug's shootout
KL> (http://www.bagley.org/~doug/shootout/) in XOTcl to see how it would
KL> fare. Specifically it was the method call speed test
KL> (http://www.bagley.org/~doug/shootout/bench/methcall/). I have attached my
KL> code to this email.

KL> According to my own tests, it didn't do terribly well, but it's difficult
KL> to say whether this is a limitation of Tcl (which doesn't do very well in
KL> several of those speed tests) or just a sign that there might be some room
KL> for optimisation in XOTcl itself. Now what would be interesting would
KL> be a comparison with iTcl -- but as I don't know it I'll leave that for
KL> someone else. Any comments?

 Dear Kristoffer,

 this test is not a very good test for xotcl, but one should not
 complain about other people's benchmarks.

 Our forthcoming version will have some significant performance
 improvements (which will be for this example in the range of 5-10%,
 for other examples we have seen up to 50%). Some of the changes were
 over-aggressive, we might have to take some of these back.

 however, i tried the example of yours in itcl, and the result was
 about 30% slower than the current development version of xotcl. i am
 not an itcl expert, so i would not wonder, if if have done something
 wrong, of if someone else get some better figures by using
 a different implementation.

 best regards
-gustaf

=============================================================================
class Toggle {
  variable state
  constructor startState {
    set state $startState
  }
  method value {} {
    return $state
  }
  method activate {} {
    set state [expr {! $state}]
    return $this
  }
}


class NthToggle {
  inherit Toggle
  variable counter
  variable countMax
  
  constructor {startState maxCounter} {
    Toggle::constructor $startState
  } {
    set countMax $maxCounter
    set counter 0
  }
  method activate {} {
    incr counter
    if {$counter >= $countMax} {
      set state [expr {! $state}]
      set counter 0
    }
    return $this
  }
}

proc main {} {
  global argv

  set n [lindex $argv 0]
  set val 1
  set toggle [Toggle t $val]

  for {set i 0} {$i < $n} {incr i} {
    set val [[$toggle activate] value]
  }
  if {$val} {
    puts "true"
  } else {
    puts "false"
  }

  set val 1
  set ntoggle [NthToggle nt 1 3]
  for {set i 0} {$i < $n} {incr i} {
    set val [[$toggle activate] value]
  }
  if {$val} {
    puts "true"
  } else {
    puts "false"
  }
}

main