20

Re-implemented a Perl-based log analysis script in plain old C to make it faster.

Horrible implementation... Good times.

Comments
  • 6
    Which one ended up more horrible, the Perl or C implementation?
  • 1
    *Following*
  • 1
    @electrineer i wanna know this as well
  • 0
    Obviously C is worse.
  • 5
    Unfortunately have to admit it was my C code. I don't have it anymore, but from what I remember the 17 year old me that had no notable prior programming experience took the following implementation strategy:

    1. Okay I need to read stuff from a text file. The way to do that is `fscanf` apparently. Let's use that.

    2. Well, shucks. These Log lines are fucking complex and I just need a tiny bit of information from each line. Okay, so I add a command line argument that tells the program to preprocess the log file and turn the complex log lines into something I can parse with fscanf. Just tell the user to run it twice. No problem.

    3. Okay, Reads the data. fine. Now process the data. Well, I don't know how many data sets I will have in the end, and running the parser twice is not an option. HA! I know it! I have just learned about these "linked lists" in school. Lets implement one of those. *implements linked list*
  • 5
    4. Okaaaay, that seems to do the trick. Now I need to sort this by time and write out the output. *implements linked list sorting*

    Finally, I think the output was something like an ASCII-Art histogram that showed how many IPs were active at the same time.

    Needless to say this program was hardly understandable by anyone (why the fuck do I have to run this two times?!?)

    It had more than a thousand lines of code for functionality that would likely be a three-liner in Python.

    **BUT**

    It ran faster than the fucking Perl Script

    **AND**

    The Perl script couldn't do the ASCII-Art histogram.
Add Comment