/mobile Handheld Friendly website

 performance measurements

Each table row shows performance measurements for this Go program with a particular command-line input value N.

 N  CPU secs Elapsed secs Memory KB Code B ≈ CPU Load
500,0000.180.18?405  0% 0% 0% 100%
5,000,0001.681.683,092405  0% 0% 1% 100%
50,000,00016.7916.793,092405  0% 1% 1% 100%

Read the ↓ make, command line, and program output logs to see how this program was run.

Read thread-ring benchmark to see what this program should do.

 notes

go version go1.2 linux/amd64

 thread-ring Go #5 program source code

/* The Computer Language Benchmarks Game
   http://benchmarksgame.alioth.debian.org/

   contributed by KP
*/

package main

import (
   "fmt"
   "os"
   "runtime"
   "strconv"
   "sync"
)

type Token int

type T struct {
   next  *T
   label int
   value int
   mux   sync.Mutex
}

func (w *T) put(v int) {
   w.value = v
   if v == 0 {
      res <- w.label
   } else {
      w.mux.Unlock()
   }
}

func (w *T) run() {
   for {
      w.mux.Lock()
      w.next.put(w.value - 1)
      runtime.Gosched()
   }
}

func (w *T) Start(label int, next *T) {
   w.label = label
   w.next = next
   w.mux.Lock()
   go w.run()
}

const NThreads = 503

var res = make(chan int)

func main() {
   n := 1000
   if len(os.Args) > 1 {
      n, _ = strconv.Atoi(os.Args[1])
   }

   var channels [NThreads]T
   for i := range channels {
      channels[i].Start(i+1, &channels[(i+1)%NThreads])
   }

   channels[0].put(n)
   fmt.Println(<-res)
}

 make, command-line, and program output logs

Mon, 02 Dec 2013 13:54:21 GMT

MAKE:
/usr/local/src/go/bin/go build -o threadring.go-5.go_run
0.36s to complete and log all make actions

COMMAND LINE:
./threadring.go-5.go_run 50000000

PROGRAM OUTPUT:
292

Revised BSD license

  Home   Conclusions   License   Play