What is QDSTAR? -*-org-*- * 2011/2/3 ... While thinking about the design of the collection of web sites I never quite get to a state of presentability, I latched onto the idea of "Papaverse", a web page somewhere easy to find that contains links to all my sites, my corner of the WWW universe, in the form of a text pseudo star map. My first attempt is here: http://papa.freeshell.org/index.html You can see that a "hand-drawn" map lacks something. OK, a pseudo star map generator program, with normally distributed stars, and multiple populations, and customizable orientation and framing ... I actually wrote something like that about fifteen years ago when the department had a couple of workstations. I wanted something more interesting for my X Windows wallpaper other than a solid color or the standard herring bone texture. Hard to believe, but that starfield generator was one of the few things I've ever programmed in C. I've often thought about recreating that program (original source is long-gone with the workstations), and now we have a tone of scripting languages tat would make the programming almost trivial. ... But if it's trivial, is it worth the effort? Why not learn something and put a new arrow in my quiver in the process? How about relearning C? OK, that will certainly be useful, especially considering the diverse and often small and old systems I usually tinker on. Have to find a good manual, and work through some tutorials, and get a compiler working on my new Zaurus, and then get sidetracked trying to find and configure all the other "essential" Zaurus software packages. ... Then I see an article about trends in programming language usage. I patted myself on the back to see that C continues to be number 1, but then the shocker: my long-beloved Perl is fading from collective consciousness! Saddened, my mind wandered back to my neglected pseudo star map generator, wondering when I'd actually be able to get C code running. Suddenly I realized that with familiar and friendly Perl, not only would the coding be trivial, not only would I be able to do it without cracking open a manual, but if I removed a few of the bells and whistles I could probably be actually generating star maps momentarily. And I did, with qdstar, the quick-and-dirty pseudo star map generator! * 2011/2/5 ... But if it's so easy in Perl, is C so much harder? No, it turns out. With a working qdstar under my belt, I tried rewriting it in C as qdstarc. It took a little more effort than the Perl version, with data declarations and casting. I also had to look up how to use the random number seed function srand(). On the other hand, while writing the C code I thought of an alternative algorithm much more efficient than the one I used in the Perl version. The original algorithm looped through all positions in the starfield to initialize everything to space, then looped through each position where a star would appear to set the character to be displayed, then looped through all positions again to print out the results. The new algorithm accomplishes everything in a single pass through starfield positions, and also eliminated the need for storing the starfield in memory during processing. My C code compiles into a 12 KB executable that runs in about one-third the time of the Perl version. Out of curiosity, I wrote a new Perl version, qdstar2, with the same algorithm I discovered for the C version. It runs a little faster than the original, but not much. Performance of the three versions is compared below. ** Performance comparison Average real time over 10 runs: |---------+-------| | qdstar | 0.242 | |---------+-------| | qdstar2 | 0.213 | |---------+-------| | qdstarc | 0.085 | |---------+-------| * 2011/2/7 ** Lessons learned - For simple tasks C is not much harder to code than Perl. - I had paralyzed myself in the analysis/education phase of programming. The original goal of writing a pseudo starfield generator in C wasn't so difficult once I relaxed a few non-essential requirements and just started programming. + Must learn to not get hung-up in less important aspects of a project (e.g. overall language knowledge, programming style, ...) - Rewriting the program in a different language was a valuable educational exercise. - Prototyping may be a valuable approach to personal projects. First program and explore in easy to write Perl, then rewrite in more difficult C once I've proved the concept to myself. - For some tasks, programming language choice has a much bigger impact on performance than algorithm.