Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo


#176 Writing PNM's is really slow

G. Myers

This isn't a bug in a functional sense, put it could be considered a bug from a performance point of view. I noticed that writing binary PNM's took a lot longer than I expected. Examining the code in il_pnm.c::iSavePnmInternal() I noticed that the problem was due to repeated calls to iputc() to write out each byte, rather than a single call to iwrite() to write out the entire image. By changing the code to use iwrite() I realized a ~9.5x speed increase on my machine. Of course this will be disk/architecture dependent, but I think it makes more sense to handle the write in this fashion.

I'm attaching my patch, but I would say that it is only partially complete. You could probably handle the IL_PBM_BINARY case more smartly to also use iwrite(). Additionally, there is probably a better way to handle the ASCII variants than repeated calls to ilprintf(), but I don't have time right now to investigate this.

One last note, in the ASCII section I commented out the code while assigned the k variable, as k was never being used.


  • G. Myers
    G. Myers

    Patch for PNM write speeds