Home > Archive > Tcl > December 2004 > Language speed [was Re: Good TK book]
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Language speed [was Re: Good TK book]
|
|
| Gustaf Neumann 2004-12-29, 8:58 pm |
| This version seems to need some finishing touch:
i have not looked in details, but found the following strangenesses:
- thread benchmark: LUA seems to create 1000 threads, not 3000
as required
- thread benchmark: Java result failed, but it is counted
- regex for tcl says: "No program", clicking on it shows a
tcl program
- ackermann runs out of stack. It should be possible to fix it
with "interp recursionlimit ..."; the following version
should be somewhat faster than the version with expr.
-gustaf
PS: Google news did not let me follow up, so i had to remove the "re:"
from the subject line.
========================================
===========================
interp recursionlimit {} 100000
set NUM [expr {[lindex $argv 0] < 0 ? 1 : [lindex $argv 0]}]
proc ack {m n} {
if {$m == 0} { incr n
} elseif {$n == 0} { ack [incr m -1] 1
} else { ack [expr {$m - 1}] [ack $m [incr n -1]]
}
}
puts "Ack(3,$NUM): [ack 3 $NUM]"
| |
| Bob Techentin 2004-12-29, 8:58 pm |
| "Gustaf Neumann" <neumann@wu-wien.ac.at> wrote
> - ackermann runs out of stack. It should be possible
> to fix it with "interp recursionlimit ..."; the following
> version should be somewhat faster than the version
> with expr.
Gustaf,
I just submitted a new ackermann.tcl setting recursion limit. I tried
replacing [expr {$m-1}] and friends with [incr m -1]. Small positive
difference for [incr n], and no difference, or perhaps even a penalty
for [incr m -1].
Bob
--
Bob Techentin techentin.robert@NOSPAMmayo.edu
Mayo Foundation (507) 538-5495
200 First St. SW FAX (507) 284-9171
Rochester MN, 55901 USA http://www.mayo.edu/sppdg/
| |
| Stefan Finzel 2004-12-30, 3:59 pm |
| A small additional gain (1-10% depending on NUM) can be won optimizing
the proc ack like
interp recursionlimit {} 100000
set NUM [expr {[lindex $argv 0] < 0 ? 1 : [lindex $argv 0]}]
proc ack {m n} {
if {$m} {
if {$n} { return [ack [expr {$m -1}] [ack $m [expr {$n -1}]]]
} else { return [ack [expr {$m -1}] 1] }
} else { return [incr n] }
}
puts "Ack(3,$NUM): [ack 3 $NUM]"
Yes [incr m -1] has a penalty and is slower than [expr {$m-1}].
But as i remember expr should be slower, or is this past?
Bob Techentin wrote:
> "Gustaf Neumann" <neumann@wu-wien.ac.at> wrote
>
>
>
> Gustaf,
>
> I just submitted a new ackermann.tcl setting recursion limit. I tried
> replacing [expr {$m-1}] and friends with [incr m -1]. Small positive
> difference for [incr n], and no difference, or perhaps even a penalty
> for [incr m -1].
>
> Bob
|
|
|
|
|