Posted by: leppie | August 21, 2007

Benchmarks

Although Lisp has never been known for it’s number crunching abilities, I normally focus on making something as fast as humanly possible.

I found a benchmark in an old Lisp PDF (mainly for computers running in the 60’s – 70’s I guess), it is called ‘tak’.

(using System.Diagnostics)

(= tak (fn (x y z)
  (if (not (< y x))
    z
    (tak (tak (- x 1) y z)
         (tak (- y 1) z x)
         (tak (- z 1) x y) ))))


(= run-tak (fn ()
  (= sw (startnew stopwatch))
  (= t (tak 24 14 6))
  (= ts (elapsed sw))
  (cwl "time: {0:f3}ms result: {1}" (totalmilliseconds ts) t)))

(to i 4
  (run-tak))

The above code executes in about 660ms in compiled/debug mode, and about 440ms in compiled/release mode. The fastest C# code I can dish up runs in about 85ms. While this may seem slow, I decided to compare it to Python and its managed cousin, IronPython. Python runs in about 2500 ms in the evaluator, while IronPython takes a whopping 11 seconds. On the other hand, IronLisp in eval mode, runs it in 2200ms. Still faster than Python!

Advertisements

Responses

  1. Leppie,
    Looks and sounds great. I know I’m not the only one keeping track of your blog and searching Codeplex. Could you please give some kind of timeline of release of code(preferrably) and/or binaries?

    Thanks.

  2. I have to press the ‘Publish’ button on Codeplex in 5 or less days, hence the code in the source control will be available, as soon as I do that. When will that happen? Probably today or tomorrow πŸ™‚

  3. Congratulations on ‘going live’ with IronLisp.

    COuld you show the code you used to benchmark Python and IronPython? Do you include startup time in your times? (from the little I can deduce from the Lisp code, I assume not!)

    Michael

  4. You can use the following code:
    def tak (x, y, z):
    if not(y < x):
    return z
    else:
    return tak(tak(x-1, y, z), tak(y-1, z, x), tak(z-1, x, y))

    It was invoked as tak (24,14,6) with time.clock() before and after the invocation. Tested on a 1.8 Code Duo.

  5. Seems comments loose formatting 😦

    Oh and thanks BTW πŸ™‚

  6. Leppie,

    Could you clarify which version of IronPython you are running and what platform/os you are running on? I see IronPython (latest sources) 2-2.5x faster than CPython on this benchmark, so I’d like to understand how your reached this conclusion.

    Thanks!
    ~Jimmy

  7. The benchmarks weren’t done terrible technically. I will setup something this weekend to see them side by side.


Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: