6 ms·
C for speed: Techniques To Transform Your Turtle Code
- RiderOfGiraffes 16y agoFrom 1991. Compiler technology has moved on since then and almost all of these transformations are done automatically for you. Hence the guideline now is to write your code to be readable. Having said that, it's interesting to see what people worried about in 1991, and worrying that people needed to be told these things. I was there - I remember it well.
- jpablo 16y agoExactly. I was thinking while reading this: "All of this makes the code harder to read and any modern compiler will catch most of this stuff anyway". Then I realized this was from 1991.
- angstrom 16y agoIronically, what really matters is limiting heap fragmentation and memory allocation. Not nearly that exciting or tricky.
- neilc 16y agoOptimizing to improve cache behavior can still be fairly tricky / counter-intuitive.
- bbulkow 16y agoI hope this was added as a peculiar historical artifact from 1991, not a statement of how to best write code today. These tricks don't work with GCC 4.1+ and i86_64. For example, in the loop section, the good trick now is to make your code accessible by the GCC vectorizer. If you turn on -fdump-tree-vect-details in GCC, you will see - for every loop - the weighting factors applied and what might have blocked the vectorizer's operation. Vectorized computing existed in 1991 - heck, 1969 - but was not commodity like today.
- 1amzave 16y agoI dunno...even being from 1991, I had actually assumed this was intended as humor. Those are all simple enough (if not entirely trivial) optimizations that it doesn't take a particularly heroic compiler to perform them, even twenty years ago I'd guess. Frankly, I got a good laugh out of it (that I thought was intended by the author).
- loumf 16y agoI was thinking something similar. I took a compiler course in college in 1990 and we were required to implement a couple of these optimizations (common sub-expressions, constant calculations). So I assume that they were considered easy.
- chipsy 16y agoYou can still use many of these techniques if you're programming a dynamic language like Python and don't want to add the dependency of a C extension yet. I've unrolled loops, reordered assignments, etc., to good effect.
- abalashov 16y ago-1 for sloppy, unreadable code and poor presentation.