[MLton-commit] r6598

Vesa Karvonen vesak at mlton.org
Mon Apr 21 04:21:05 PDT 2008


Added comment/discussion and removed uses of unsafe array operations.
----------------------------------------------------------------------

U   mltonlib/trunk/org/mlton/vesak/toys/spectral-norm/spectral-norm.sml

----------------------------------------------------------------------

Modified: mltonlib/trunk/org/mlton/vesak/toys/spectral-norm/spectral-norm.sml
===================================================================
--- mltonlib/trunk/org/mlton/vesak/toys/spectral-norm/spectral-norm.sml	2008-04-20 22:04:23 UTC (rev 6597)
+++ mltonlib/trunk/org/mlton/vesak/toys/spectral-norm/spectral-norm.sml	2008-04-21 11:21:04 UTC (rev 6598)
@@ -4,14 +4,39 @@
  * See the LICENSE file or http://mlton.org/License for details.
  *)
 
+(*
+ * This is an implementation of the Spectral Norm toy benchmark from the
+ * ``Computer Language Benchmarks Game'' (TheGame).  Compared to the
+ * SML/MLton version of the benchmark in TheGame at the time of writing,
+ * this one reuses a part of the logic, namely one of the multiplication
+ * functions, by using a higher-order function.  This version also makes
+ * use of a library of iterator combinators rather than a hand written
+ * tail recursive functions or a special purpose for-function.
+ * Nevertheless, performance stays the same, because MLton specializes the
+ * code, eliminating the abstraction penalty.  As a result, this
+ * implementation is significantly shorter than the implementation in
+ * TheGame.
+ *
+ * This benchmark is clearly compute bound.  Disabling array bounds and
+ * integer overflow checking
+ *
+ *   -const 'MLton.safe false'
+ *   -const 'MLton.detectOverflow false'
+ *
+ * improves performance a little---although this is probably processor
+ * dependent, because the inner loops are shortened quite a bit.  It would
+ * seem that the main bottleneck is the floating point divide, which is an
+ * exceptionally costly instruction (long latency and unpipelined) on most
+ * processors.
+ *)
+
 open Array Cvt Iter
 
-val op @ = Unsafe.Array.sub
-val update = Unsafe.Array.update
+val op @ = sub
 
 val n = valOf (Int.fromString (hd (CommandLine.arguments ()))) handle _ => 1
 
-fun aij i j = 1.0 / Real.fromInt ((i+j) * (i+j+1) div 2 + (i+1))
+fun aij i j = 1.0 / real ((i+j) * (i+j+1) div 2 + (i+1))
 
 fun timesAv aij u v =
     upTo n $ (fn i =>




More information about the MLton-commit mailing list