Fetching latest commit…
Cannot retrieve the latest commit at this time.
|Failed to load latest commit information.|
See Article, "Is Scala really more complicated than Java?" by Dick Wall http://www.artima.com/weblogs/viewpost.jsp?thread=268561 I kinda favoured the old school (Java-like) approach since it's very direct and doesn't create any extraneous data structures. Strangely enough performance is much better with the very functional version provided by Vassil. The actual Java code, OldSchool (in Scala) and dick2 and dick3 are all about the same. Very slow is dick1 - probably caused by the call to format. The main reason that the functional code is faster is because there's less IO. i.e. less calls to println (consequently less syscalls). This is because the entire 4 line jingle is created with mkString into an in memory string before it's written out. Even with output redirected to /dev/null the functional version still comes in ahead because of this (see below). On the old laptop I'm currently running, the results from run.sh are: -- With stdout redirected to run.out -- Dick Java took 4657ms (4.657s) dick1 took 13731ms (13.731s) dick2 took 5057ms (5.057s) dick3 took 5022ms (5.022s) OldSchool took 5432ms (5.432s) vassil1 took 2436ms (2.436s) vassil2 took 5337ms (5.337s) martin1 took 5700ms (5.7s) martin2 took 2322ms (2.322s) -- With stdout redirected to /dev/null -- Dick Java took 1841ms (1.841s) dick1 took 9162ms (9.162s) dick2 took 1783ms (1.783s) dick3 took 1811ms (1.811s) OldSchool took 1927ms (1.927s) vassil1 took 1157ms (1.157s) vassil2 took 1852ms (1.852s) martin1 took 2034ms (2.034s) martin2 took 1005ms (1.005s) The memory profiles are probably different but this is me now thinking differently about very functional/Haskell/O'Caml style code! Even in Scala :)