Monday, November 3, 2014

0006 - Sure, it's simple, but I like it

This semester, I'm in COMP 4040 (Programming Languages). The big assignments in this class are all pretty much the same thing: take a text-based adventure game originally written in Prolog (nifty language, but I don't care for writing in it), and translate it to other languages that we are learning about.

Well, the C++ translation was due last night at 11:59 pm. I finally gave up on trying to optimize it and turned in what I had at about 11:50, but that didn't sit well with me. Before I go down that road, I do want to fill you in on a few things about me that you may or may not already know:
1. I am a serial optimizer. I may write a quick and dirty piece of code to get a job done, but I can never let sleeping dogs lie: I have to eventually come back and clean it up, making it run faster, smoother, more error-free.
2. I'm finally learning C++. I tried picking it up when I was 12, but it was hard to find info, I had no idea what a compiler was, and the code looked scary, so I deemed it Too Hard and maintained that stance until this past summer. As such, I'm excited that I'm able to write some C++ now, and am finding it very fun.

So, since I am a serial optimizer, I'm just now learning C++, and I find C++ to be fun, I couldn't let the code I turned in last night just stay as it was. As such, I spent about 5-6 hours today trying to figure out ways to make it better.
The version I turned in last night could run from start to finish (automated tasks ftw!) in an average of .135 seconds. Since the other students I talked to had their running in just over 1.0 seconds, I originally felt pretty good about that. However, I knew there were a few things I could change to speed mine up, so I started tinkering...and tinkering...and tinkering. After trimming .01 seconds off of the run time (down to .125s), I decided that, surely, the code could be better optimized, and that I should be able to get the run time down to under 0.1 seconds.

Long story short, after another 5 hours of tinkering, I managed to get the run time down to an average of .057 seconds (less than half of the time when I started). Why am I so excited about this? Because I set an uncertain goal in a still largely unknown language, and accomplished what I set out to do. Also, because my friend Nathan said I was crazy and might have said that I couldn't pull it off (I don't listen well, so I just put words in people's mouths). So, if someone's interested in checking out what I did, leave a comment asking for the code (or ask me in person), and I'll send you the whole kit and caboodle (code, configuration files, etc.). After all, 345 lines is too much to have to read in this poorly formatted blog.

No comments:

Post a Comment