Algorithmic ownage

I felt good when I simplified one of my algorithms and sped it up 10 times. I felt so good that I even wrote an entire blog post about it patting myself on the back. Then last week I got an email from Kevin of Keming Labs suggesting a few alternatives.

First of all, his solutions looked much cleaner than mine. Then over the weekend I was able to incorporate his 3 algorithms into my program. I ran a few benchmarks and here are the average of 2 tests using a dataset of 28,760 items.

My algorithm. Elapsed time: 68372.026532 msecs.
Kevin’s solution #1. Elapsed time: 156.940976 msecs.
Kevin’s solution #2. Elapsed time: 60.165483 msecs.
Kevin’s solution #3. Elapsed time: 296.162042 msecs.

Total ownage.

That’s what I like about sharing my work; once in a blue moon, a random person drops by and generously show me how I can improve a solution 1,000 times! Now the ball is in my hands to understand what he has done and improve myself.

Collaborating and learning, that’s why I open source.

Update: I’ve done some more digging and it seems that one of the reasons for the drastic improvement in performance is due to the use of transients in the built-in functions. Lesson of the day, leverage the language’s inherent optimization by staying with core data structures and functions as much as possible.

Related posts:

  1. My first food poisoning experience

2 Comments

  1. david4505 says:

    I am thinking of using Clojure to cobble together useful components for a trading system domain specific. Language. Do you or others see Clojure as a good choice?

  2. Paul says:

    I am already using Clojure to develop trading systems.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>