michaelschader/mason-scripting — pull request #1 by rlegendi (2013-06-20 21:38:52+00:00)
Title: Scala version of the benchmark script

Hi!

Scala is quite popular recently so I thought it would be nice to include it in your measurements :-) I'm not familiar with the method how you measured the performance, but I think it will be useful for the comparison anyway.

I think you'll like it: you said at the conference that you liked the Jython version the most which is actually quite similar to the Scala one (I tried to keep similarity because heavy modification of the code might distorse the performance comparison).

# Notes #
- This is the *script* version of the MASON CA variant in Scala. It can be executed without compilation with the a simple `scala` command (I've also included a similar script you made for the others). Using a compiled version might be more effective.
- There might be some differences by using lists instead of arrays in the script.
- It might be a bit more concoise to use pattern matching rather than counting the values, something like:

neighbours match {
case (2,0) => live
case _ => die
}

The reason why I used the similar approach is to get a bit more sensible comparison between the compared platforms.
- Tested it on Scala 2.10.1, but there might be some performance differences between the versions.
I'd recommend trying 2.8.2, 2.9.3 and 2.10.2 too, would be interesting to see if there are differences in performance (I'd say there surely are).
- Basically the script is quite similar to Jython, the main difference is probably the required type notations for the function parameters (since Scala is statically typed). All the other types are inferred by the compiler. I wanted to preserve the original structure, except a few places where I was able to reduce the code considerably (e.g., in the `step()` method).

- It would have been nice to write a few tests, because they have been made in a descriptive fashion, e.g.:

val block = """|000
|011
|011""";

val glider = """|0000
|0001
|0101
|0011""";

def parseStateAndUseInsteadOfBHeptomino(s: String) = {
s.stripMargin.split("\n").map(_.toArray)
}

Then call the script and verify the results. The thing is that the other scripts were written in a fashion that they do not handle any inputs and do not generate any output that can be verified, so I decided to evade any additional operations to prevent unnecessary overhead in the benchmarks.