Sep 27

High performance numerics with F#

We stumbled upon an interesting result recently whilst toying with numerical benchmarks ported from OCaml. Typically, OCaml programs are very easy to port but run more slowly under F# because the performance characteristics of the languages are different. However, we recently observed that some benchmarks optimized for OCaml actually run substantially faster in F# without having to make even a single change.

Specifically, the OCaml implementations of the numerically-intensive spectral-norm and n-body benchmarks from the Computer Language Shootout run more quickly in F#. We believe the reason is essentially that Microsoft’s .NET compiler is much better at optimizing simple numerical algorithms, particularly loops over floating point arrays. Indeed, the results are all the more compelling because F# on vanilla 32-bit Windows XP Pro outperforms a longer, hand-optimized OCaml implementation running on OCaml’s best-case platform for numerical programs, 64-bit Linux. In particular, bounds checking incurs a significant overhead in the spectral-norm benchmark and, we believe, the bounds checks are automatically hoisted from the inner loop in F# but this must be done manually in OCaml.

  OCaml F#
Spectral-Norm 14.353 9.374
N-Body 9.469 6.933

This clearly shows that F# can achieve excellent performance on common machines for an important class of numerical algorithms.

Sep 27

Implementing the FFT

“Writing an implementation of the Fourier transform is an excellent lesson in algorithm design and optimization. Moreover, the Fourier transform is one of the most essential tools in numerical computing, with applications ranging from spectral analysis to the multiplication of large integers. This article describes the design and implementation of a simple but efficient FFT…”

Sep 27

Cool Links III- .NET 3.0, 3.5, Acropolis, TFS, AJAX, VSTS

I posted a few sets of links a few months ago. Here is another list. There has been a ton of new info to keep up with. Topics - .NET 3.0, 3.5, Acropolis, TFS, AJAX, Visual Studio 2008, CAB, WPF, Silverlight, SQL Server 2008, Architecture, WCF, LINQ, MVP, Repository Factory, etc…