Version 19 of thread-ring benchmark

Updated 2008-06-06 04:51:09 by jmn

See http://shootout.alioth.debian.org/gp4/benchmark.php?test=threadring&lang=all


jmn I tried the following, but it errors out with "can't create a new thread" - even though my system appears to have plenty of free memory.

Any ideas as to what limit I'm hitting?

escargo 4 Jun 2008 - Well, how about telling us what version of Tcl and system you are using, plus a description of its hardware resources?

jmn Tcl 8.5.2b1 - Vista x64 - core2 2.4Ghz 4G ram

It seems to produce the error for ring_size >= 206

 - also, due to the above error, I haven't verified that the code below produces the right result. 

If anyone else runs it sucessfully, please make a note here as to whether it produces the expected result for N = 1000, of 498; thanks.

SL I can create up to ~800 threads. I guess to run this script in the same shell multiple times you have to release some threads.

Nresultsecssystem
10004982.46Tcl 8.5.2 - XP x86 core2 2.0GHz
10,000,000361336.51Tcl 8.5.2 - XP x86 core2 2.0GHz

jmn Thanks for that. A little disappointing given your machine seems similar but a little more powerful than the actual machines used for the benchmark - but still seems not too bad.

Ahh well, if we can't beat them on performance - we can still be right up there for gzip bytes & linecount.. see v2 for a more compact version.


V1

 set ring_size 503
 set N 1000
 package require Thread
 proc done {} {
 	set ::done 1
 }
 set script {
 	proc accept {t} {
 		if {$t == 0} {
 			puts stdout "%i%"
 			thread::send -async %m% done
 			return
 		}
 		thread::send -async %n% [list accept [expr {$t - 1}] ]
 	}
 	%do%
 }
 set t1 [set tnext [thread::create {thread::wait}]]
 for {set i $ring_size} {$i >1} {incr i -1} {
  	set tnext [thread::create [string map [list %m% [thread::id] %i% $i %n% $tnext %do% "thread::wait"] $script]]
 }
 #close the ring
 set script [string map [list %m% [thread::id] %i% 1 %n% $tnext %do% [list accept $N]] $script]
 thread::send -async $t1 $script
 vwait ::done 

v2 (slightly slower)

 package require Thread
 set ring_size 203
 set N 1000
 set script { 
	interp alias {} accept0 {} thread::send -async %m% "set ::done %i%"
 	interp alias {} accept1 {} apply {t {thread::send -async %n% "accept[expr {$t>1?1:0}] [expr {$t-1}]"}}
 	%do%
 }
 set t1 [set tnext [thread::create {thread::wait}]]
 for {set i $ring_size} {$i >1} {incr i -1} {
 	set tnext [thread::create [string map "%m% [thread::id] %i% $i %n% $tnext %do% thread::wait" $script]]
 }
 thread::send -async $t1 [string map "%m% [thread::id] %i% 1 %n% $tnext %do% {accept1 $N}" $script]
 vwait ::done
 puts stdout $::done