Next | Making Programs Faster | 139 |
My friend Walt wrote a program to solve a math puzzle
Find 'excellent numbers' like 190476 or 48
4762 - 1902 = 226576 - 36100 = 190476
82 - 42 = 64 - 16 = 48
Walt's program had
sub square { return $_[0] * $_[0] }
Since square was called a lot, he memoized it
Now the program was slower
Here's why
Next | Copyright © 2003 M. J. Dominus |