I really hate waiting for slow programs

Tip: in Matlab, whenever you’re having speed issues, the usual solution is to reduce the number of statements within your loops. You’ll usually see a dramatic improvement.

Normally I don’t post much about work, but I just had a great moment and had to write about it. It all started while I was making a script to merge data from two different formats and remove the overlapping datapoints. It was working, but was way too slow – it took over two minutes to complete, and you know how much I hate waiting.

So like I normally do when I want to speed up my code, I opened up the profile viewer tool. It told me that waitbar and datevec were taking over 50 seconds each, which I found to be totally unacceptable.

Instead of using datevec line by line, I could use it only once on the whole vector, then reference full columns of the output. That would do everything all at once, for all 600k entries. Speed is the whole point of using Matlab in the first place, why not take advantage of it?

Imagine how happy you would be if you found out you not only gained the ability to brush your teeth in 1/100th the time, but could also schedule a robot to do it in your place – that’s how I feel when I fix stuff like this.

My code went from this:

for i = 1:n
h = waitbar(0);
x                   = datevec(TS.datenum(i));
X.year(i)           = uint16(x(1));
X.month(i)          = uint8(x(2));
X.day(i)            = uint8(x(3));
totalvolume         = totalvolume + TS.volume(i);
X.totalvolume(i)    = totalvolume;
X.volume            = TS.volume(i);
end;

for i = 1:n
h = waitbar(0);
x = datevec(TS.datenum(i));
X.year(i) = uint16(x(1));
X.month(i) = uint8(x(2));
X.day(i) = uint8(x(3));
totalvolume = totalvolume + TS.volume(i);
X.totalvolume(i) = totalvolume;
X.volume = TS.volume(i);
end;
Run time: 157 seconds

To this:

a = datevec(TS.datenum);
% datevec insta-runs for 600k entries!
X.year      = uint16(a(:,1));
X.month     = uint8(a(:,2));
X.day       = uint8(a(:,3));

for i = 1:n
totalvolume = totalvolume + TS.volume(i);
X.totalvolume(i) = totalvolume;
end;
Run time: 1.331 seconds

It’s finding the dramatic improvements like these that make me like my job.

Posted in work-related | Tagged , | Leave a comment

Making progress on automation of data download

What I love about automating things, is that once you figure out how to do something once, you can do it a million times more for only a tiny bit more work.

Only two weeks ago, I was struggling with matlab to download even one line of data from a tcpip socket. But once I figured out a few relevant commands, everything started falling into place.

  1. It all started when I figured out how to load a dll and connect to the socket.
  2. Eight days ago I figured out how to read a single line from the socket.
  3. Seven days ago I learned how to quickly parse the line into separate fields.
  4. Six days ago I solved how make sure the data was clean and downloaded a full day’s worth of data for one contract.
  5. Five days ago I went to the Del Mar Racetrack with my coworkers and relaxed the rest of the weekend in San Diego.
  6. Then yesterday I made some more incremental improvements and downloaded 8 days worth for 3 contracts.
  7. Today I finished an automated program that downloaded over 2 million lines from IQfeed, with the ability to queue up a pretty much unlimited amount for the future.

The limit imposed by our data provider (DTN IQfeed) is 30 days worth. I think I’ll schedule a download once every week. It’s great because now that I’ve finished with that program I can move on to bigger and better things, while the fruit of my labor grinds it out for me downloading massive amounts of data.

Posted in work-related | Tagged | Leave a comment

In programming, “kind of” working is never acceptable.

I got a really big feature done last week that involves finally getting streaming data into Matlab through a socket connection.  It works – kind of.  Too bad “kind of working” isn’t enough to anything, since the goal is automation and reliability.  Today I found all sorts of holes in it that will be driving me nuts for days, until I can find fixes for them.

Sometimes the feed will randomly drop a few minutes of data at a time. Sometimes the feed will stop sending in the middle of a line and start a new line, causing the loss of just one transaction. I’m not sure if this is the fault of the feed or the way that I programmed it, but it’s probably my fault somehow. ARGH I hate partially working instable programs!!!!

Posted in work-related | Tagged , | Leave a comment

code it up

I found a pretty cool link just now, to a guy who attempts to recreate the copyrighted THX theater sound using a sound programming framework called SuperCollider.  The code is pretty intense and I didn’t even try to understand it, I just listened to the outputs as he layers the transformations.  The part that I thought was amazing was that the original sound took 20,000 lines of code and was the combination of 30 oscillators being dynamically generated in real-time, which took the entire processing power of the ASP computer at the time.  But the recreation of it in SuperCollider takes fewer than 100 lines of code to very closely recreate the same sequence.  At the end of the example, the author roughly recreates the sound in only 140 characters, pretty amazing…

This is something I’ve been thinking about for a while as I learn programming for work – the development of enabling technologies as a requirement for progress.  The initial task may be incredibly difficult as it is first being done, but once it is understood it can be built into a framework that simplifies things exponentially for all future users.  It allows users of the tool to take it to the next level of artistic expression because of how easy it is to produce new samples.  This is how the art is made, based on the contributions of innovators who paved the way.  Users who would have a difficult time simulating or understanding even a single synthesizer on their own, once given the framework to do so can think of amazingly creative things to do with it.

(more…)

Posted in work-related | Tagged | Leave a comment

I just trained under daisyxoxo at Ari’s Training Center.

Jeremy “daisyxoxo”, a serious contender for Bluff 2009 Online Poker Player of the Year, is now teaching at Ari’s Training Center in Las Vegas!

Myself and a bunch of other students are out here to find out how he’s been winning so consistently for the past 2 years.  He humbly states that even 2 years is not “long run” as far as poker goes but whatever, he is still a beast, playing a million tables at once and building huge stacks regularly.  I took over 5 pages of notes already, it’s a race to learn as much as I can by the time I have to leave on tuesday!

Also posted in blog entries | Tagged , , , | Comments closed