Bones' Blog of Stuff About Things

03 Jul

River Wild

So I’ve got working C versions of the rain, water flow and erosion processes and the news on the speed-up is that, on average, it’s about 5 times as fast as the Python variant for the erode, but for some reason it seems to be far far faster for the flow calculation — something like 20 times faster. I haven’t measured exact differences as I made some algorithm changes as I converted and so it wouldn’t be a fair comparison anyway. It’s both enough to have made the exercise worthwhile and yet not quite as much as I really expected.

I’d say that I’ve spent about half my time dealing with my rusty C skills and the need to replace functionality that Python just provides out of the box (so the C extension has its own list replacement) and half the time still playing around with the actual river erosion algorithm itself. It’s still not in a state I’m happy with, but I’m going to draw a line under it for now. I can generate some maps that have reasonable rivers and so I’ll move on with those.

Outside of the speed-boost, the conversion was useful in giving me a new perspective on how the whole thing might be structured, so it was definitely worthwhile. Now I have a decent idea how I can create Python code so that it the performance sensitive parts can be converted to C without too much hassle. This should be very useful, particularly if I have PyUnit tests to back up the process. Flipping between Python and C code would seem to potentially offer the best of high-level, OO, low-level and procedural worlds, so it will be very interesting to see how this pans out.

Leave a Reply

© 2012 Bones' Blog of Stuff About Things | Entries (RSS) and Comments (RSS)

GPS Reviews and news from GPS Gazettewordpress logo