/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
5000.170.18?536  0% 0% 0% 100%
3,0006.186.19956536  0% 2% 0% 100%
5,50020.7620.771,212536  0% 1% 1% 100%

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

Read spectral-norm benchmark to see what this program should do.

 notes

go version go1.2 linux/386

 spectral-norm Go #3 program source code

/* The Computer Language Benchmarks Game
 * http://benchmarksgame.alioth.debian.org/
 *
 * contributed by K P anonymous
 */

package main

import (
   "flag"
   "fmt"
   "math"
   "runtime"
   "strconv"
)

var n = 0    // var n = flag.Int("n", 2000, "count")
var nCPU = 4 // var nCPU = flag.Int("ncpu", 4, "number of cpus")

type Vec []float64

func (v Vec) Times(ii, n int, u Vec, c chan int) {
   ul := len(u)
   for i := ii; i < n; i++ {
      var vi float64
      for j := 0; j < ul; j++ {
         vi += u[j] / float64(((i+j)*(i+j+1)/2 + i + 1))
      }
      v[i] = vi
   }
   c <- 1
}

func (v Vec) TimesTransp(ii, n int, u Vec, c chan int) {
   ul := len(u)
   for i := ii; i < n; i++ {
      var vi float64
      for j := 0; j < ul; j++ {
         vi += u[j] / float64(((j+i)*(j+i+1)/2 + j + 1))
      }
      v[i] = vi
   }
   c <- 1
}

func wait(c chan int) {
   for i := 0; i < nCPU; i++ {
      <-c
   }
}

func (v Vec) ATimesTransp(u Vec) {
   x := make(Vec, len(u))
   c := make(chan int, nCPU)
   for i := 0; i < nCPU; i++ {
      go x.Times(i*len(v)/nCPU, (i+1)*len(v)/nCPU, u, c)
   }
   wait(c)
   for i := 0; i < nCPU; i++ {
      go v.TimesTransp(i*len(v)/nCPU, (i+1)*len(v)/nCPU, x, c)
   }
   wait(c)
}


func main() {
   flag.Parse()
   if flag.NArg() > 0 {
      n, _ = strconv.Atoi(flag.Arg(0))
   }
   runtime.GOMAXPROCS(nCPU)

   u := make(Vec, n)
   for i := range u {
      u[i] = 1
   }
   v := make(Vec, n)
   for i := 0; i < 10; i++ {
      v.ATimesTransp(u)
      u.ATimesTransp(v)
   }
   var vBv, vv float64
   for i, vi := range v {
      vBv += u[i] * vi
      vv += vi * vi
   }
   fmt.Printf("%0.9f\n", math.Sqrt(vBv/vv))
}

 make, command-line, and program output logs

Mon, 02 Dec 2013 10:01:01 GMT

MAKE:
/usr/local/src/go/bin/go build -o spectralnorm.go-3.go_run
0.39s to complete and log all make actions

COMMAND LINE:
./spectralnorm.go-3.go_run 5500

PROGRAM OUTPUT:
1.274224153

Revised BSD license

  Home   Conclusions   License   Play