interpreted versus compiled


MATLAB is a math language.  it's all about high level math with matrices, really efficient and supposedly fast, and extremely powerful... it has an image analysis toolbox, which is really cool, so i thought, i can use that.

what happened was, i got a tiff that was too pale.  we'd scanned some dots, and they were too small and pale to show up in the analysis software we had, so i thought, if i make the dots darker they might show up.... that's like adjusting the contrast, but i don't trust the GIMP or XV to do it because you never know exactly what it's going to do.

so i loaded this tiff in matlab and started chunking through it.

  1. find the minium gray value in the image.
  2. subtract that minimum from every pixel.
  3. find the new maximum.
  4. multilpy every pixel by 255/(new maximum)


and that should stretch the contrast to the full range, right?  right.

so i wrote like ten lines of code to do just that, and ran it.  and waited.  and waited.  and waited.  and two minutes later it stops because it finally got to a bug.

MATLAB is like perl, it's interpreted.  and it has garbage collection and bounds- and type-checking and all sorts of other things --- that makes it slow.  that makes it frustrating.

so while i was waiting i coded up the scaling algorithm in C.  and the max algorithm.  and the min algorithm.  and something to read a PGM file.  and something to write a PGM file.  and then a main that would read a filename from the command line and do all this stuff to it.

then there was another program that converts tiffs to pgms, and yet another program that converts PGMs to tiff (i already knew about these, part of the netpbm package, that's why i chose the PGM ;-).

so i ran my C program.

it took 0.80 seconds.

my matlab program still hadn't finished yet on the most recent debug run.

*sigh*

so i got finished output and was using it before i'd worked all the kinks from the matlab version.  and then i put a timer in the matlab one just to find out how long it took...

MATLAB script: 3:53
C executable: 0.01

hmm....  don't know what to think about that one....

Wed Aug 11 22:44:27 EDT 1999