The Technology Behind the Tech

I started developing HALO portfolio-optimization software just shy of 1.5 years ago.  I owned a Linux workstation with a simple RAID-1 file system running Debian Linux, and I was on a 8-week sabbatical from work.  I started development using Ruby 1.8.7.  Later I switched to Ruby 1.9.1, then 1.9.3.  I have chosen, for now, to remain “frozen” on the 1.9.3 Ruby implementation.

I chose Ruby as my primary prototyping language because it allows rapid development, intuitive and highly-readable code, and easy of debugging.  Moreover, the Ruby HALO code is highly portable: The code developed Linux ran identically on Window with little to no modification.  After the initial development push that produced 3-D optimization graphs, I began developing on Windows under Cygwin.  I did this for three reasons.  1)  I wanted to run and test on Windows, 2) I had a Windows laptop and wanted to be able to develop anywhere: at the park, at the coffee shop, on an airplane, etc.  3)  I wanted to bring and demo my software to potential investors and potential clients.  I periodically sync the code between my Windows laptop and my Linux desktop.

Eventually, I began to wonder how much run time performance I was giving up by using Ruby instead of C/C++.  I profiled the Ruby code and began re-implemented the most compute-time-intensive parts of the code in C/C++.  Finding C++ a bit lacking by itself, I began using C++11 with Boost.  I am currently using Boost 1.53.0.

I was expecting perhaps a 10X speed up, but was happily surprised that I saw speed ups of between 20X and 50X when converting from Ruby to C++.  The C/C++ implementation is not a line-by-line parroting of the Ruby code, but the algorithms remained the same.  Coding in C/C++ caused me to focus more on memory allocation and, yes, garbage collection, so I attribute part of the massive speed up to that.

(I also tried JRuby — compiling the Ruby code to Java bytecode and running on the JVM.  I did see a speedup, but only about 15%.)

To date I have converted less than half of the Ruby to C++.  Currently the complete HAL0 Suite is 70% Ruby, 26% C++, and 4% other (Perl, Shell, etc).  By converting the most critical algorithms to C++, overall run time has improved approximately 3.5X.  Less than 10% of the end-to-end run time is consumed by the C++ portion.  That leads me to believe that an additional 10X performance increase is likely by the time I convert to a 100% C++ implementation.  [All of my run-time benchmark data are based on runs on an Intel(R) Core(TM) i5-2467M CPU @ 1.60GHz.]

My current C++ compiler is gcc 4.5.3.  All the C++ benchmarks above were performed with no compiler optimization (-O0).  Simply switching to “-O2” optimization resulted in a 15.6% performance boost.  I plan on experimenting with other flags starting with some suggestions from this GCC Intel x86 performance webpage. I will admit I have a bias toward Intel hardware.  That being said, it likely be a long time before I choose to plunk down $699 x 2 of Sigma1 Financial’s capital to buy even the basic Intel C++ compilers for Windows and Linux.

I ordered an Intel Core i7-4770K (desktop) system for Sigma1 Financial within a day of the chip’s official release.  It is scheduled to arrive next week.  Naturally, I am excited to see how much performance gain results from jumping two CPU generations and over 2X in core frequency.



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your 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 )

Connecting to %s