The Q6600
Benchmarks Game

spectral-norm VW Smalltalk program

source code

"* The Computer Language Benchmarks Game
    https://salsa.debian.org/benchmarksgame-team/benchmarksgame/
    contributed by Paolo Bonzini 
    reworked by Isaac Gouy *"!

Smalltalk.Core defineClass: #BenchmarksGame
    superclass: #{Core.Object}
    indexedType: #none
    private: false
    instanceVariableNames: ''
    classInstanceVariableNames: ''
    imports: ''
    category: ''!


!Core.BenchmarksGame class methodsFor: 'private'!

spectralnorm: n
   | u v vBv vv |
   u := Array new: n withAll: 1.0d0.
   10 timesRepeat:
      [v := u multiplyAtAv.
       u := v multiplyAtAv].
   vBv := 0.0d0.
   vv := 0.0d0.
   1 to: n do:
      [:i |
       vBv := vBv + ((u at: i) * (v at: i)).
       vv := vv + ((v at: i) * (v at: i))].
   ^(vBv / vv) sqrt! !

!Core.BenchmarksGame class methodsFor: 'initialize-release'!

do: n
   Stdout
      print: (self spectralnorm: n) digits: 9;
      nl.

   ^''! !


!Core.SmallInteger methodsFor: 'benchmarks game'!

matrixA: anInteger
   ^1.0d0 / ((self + anInteger - 2) * (self + anInteger - 1) /2  + self)! !


!Core.Array methodsFor: 'benchmarks game'!

multiplyAtv
   | n atv sum |
   n := self size.
   atv := Array new: n.
   1 to: n do: [:i|
      sum := 0.0d0.
      1 to: n do: [:j|
         sum := sum + ((j matrixA: i) * (self at: j)) ].
      atv at: i put: sum].
   ^atv!

multiplyAtAv
   ^(self multiplyAv) multiplyAtv!

multiplyAv
   | n av sum |
   n := self size.
   av := Array new: n.
   1 to: n do: [:i|
      sum := 0.0d0.
      1 to: n do: [:j|
         sum := sum + ((i matrixA: j) * (self at: j)) ].
      av at: i put: sum].
   ^av! !


!Core.Stream methodsFor: 'benchmarks game'!

nl
   self nextPut: Character lf!

print: number digits: decimalPlaces
   self nextPutAll: 
      ((number asFixedPoint: decimalPlaces) printString copyWithout: $s)! !

    

notes, command-line, and program output

NOTES:
64-bit Ubuntu quad core
VisualWorks® 8.3 Aug 19 2017




Sun, 10 May 2020 04:55:41 GMT

MAKE:
cp /opt/src/vw8.3pul/image/visualnc64.im spectralnorm.vw_run.im
/opt/src/vw8.3pul/bin/visual spectralnorm.vw_run.im -nogui -pcl MatriX -filein spectralnorm.vw -doit 'ObjectMemory snapshotThenQuit'

Autoloading MatriX from $(VISUALWORKS)/preview/matrix/MatriX.pcl
Autoloading Xtreams-Support from $(VISUALWORKS)/xtreams/Xtreams-Support.pcl
Autoloading Xtreams-Core from $(VISUALWORKS)/xtreams/Xtreams-Core.pcl
Autoloading Xtreams-Terminals from $(VISUALWORKS)/xtreams/Xtreams-Terminals.pcl
Autoloading Xtreams-Transforms from $(VISUALWORKS)/xtreams/Xtreams-Transforms.pcl
Autoloading Xtreams-Substreams from $(VISUALWORKS)/xtreams/Xtreams-Substreams.pcl
Autoloading Xtreams-Multiplexing from $(VISUALWORKS)/xtreams/Xtreams-Multiplexing.pcl
Filing in from:
	spectralnorm.vw
BenchmarksGame class<private
BenchmarksGame class<initialize-release
SmallInteger<benchmarks game
Do you want to add Root.Smalltalk.Core.SmallInteger>>matrixA: to the previously unchanged package, Magnitude-Numbers
						OK to continue?
Array<benchmarks game
Do you want to add Root.Smalltalk.Core.Array>>multiplyAtv to the previously unchanged package, Collections-Arrayed
						OK to continue?
Stream<benchmarks game
Do you want to add Root.Smalltalk.Core.Stream>>nl to the previously unchanged package, Collections-Streams
						OK to continue?
/home/dunham/benchmarksgame_quadcore/spectralnorm/tmp/spectralnorm.vw_run.im created at May 9, 2020 9:55:08 PM
9.89s to complete and log all make actions

COMMAND LINE:
/opt/src/vw8.3pul/bin/visual spectralnorm.vw_run.im -nogui -evaluate "BenchmarksGame do: 5500"

PROGRAM OUTPUT:
1.274224153