I decided very recently to re-learn my college linear algebra course with the goal of eventually moving on to deep machine learning neural networks. Additionally, I recently started reading Make it Stick and found many of the arguments compelling for retaining what I’m learning. One of the theories says, “that if you combine multiple subjects and work through practice problems regularly your results will be much better than if you just read a textbook even multiple times”. Thus, I decided that while I’m re-learning linear algebra I would additionally learn how to program in the Lua programming language. This is the product of my work so far. So far, I’m loving lua for it’s simple constructs and speed while offering a more accessible syntax than something like C or C++.
As you can see from the source code, I decided to do a speed test for matrix multiplication comparing my implementation written in lua, and executed via luajit vs torch vs ruby. The reason why I tested against ruby is becuase, ruby is my language of choice (for it’s beautiful syntax), when it comes to most things and I wanted to see just how good or bad it really was when it comes to raw computation. The results speak for themselves, and although I wasn’t surprised that ruby was the slowest, I was surprised how much slower it was.
For the interested, here are the results of the tests running all on the same hardware m3.medium instance on AWS (Amazon Web Services).
Lua matrix multiplication written by me
Ruby matrix multiplication Stdlib
Lua matrix multiplication Torch framework
To summarize, Torch (written for lua) is amazingly fast, literally 20 times faster than ruby and 7 times faster than my simplistic lua implementation. Another interesting datapoint is that the simple lua program I wrote is almost 3 times as fast as the ruby implementation suggesting that luajit is just a higher performance language.
The moral of the story is this, if you want to learn linear algebra or play around with toy problems then by all means program your own framework or use something like ruby. However, if you are planning to do serious computation, it pays to look at tools that are optimized for raw computation.
With promising results like this, I’m looking forward to doing more work with Torch once I’ve refreshed my memory with the basic computation and practical application of linear algebra.