Ten Times Faster
You'll profile a slow program, find the one function eating most of the time, and make the whole thing ten times faster.
About
Guessing where a program is slow is wrong almost every time, and the profiler knows. Take something of yours that takes more than ten seconds, measure it, and fix only what the measurement says. Most ten-times speedups come from one data structure change or one loop that was doing the same work a thousand times. Rewriting it in a faster language doesn't count here.
At a glance
- Per requirement
- 35 XP
- Completion bonus
- 300 XP
- Requirements
- 6
- Takes
- Two weeks
- Skill level
- Intermediate (months of practice)
- Cost
- Free
- Supplies
- Nothing special
- Where
- At home
- Other people
- On your own
Requirements
-
1
Pick a program of yours that takes at least 10 seconds on a realistic input, and record the baseline. Time it three times and take the median. Save the input so every run is the same. Take a screenshot of the three timings. Photo
-
2
Run a profiler and find the top ten functions by time. Use cProfile, node --prof, go tool pprof, or whatever your editor has built in. Sort by cumulative time. The top function is usually a surprise. Take a screenshot of the profile output. Photo
-
3
Fix the top hotspot and nothing else, then measure again. Make one change and re-run the timing. Write down what the change was, with the before and after numbers. If it didn't help, undo it and read the profile again. Take a screenshot of the new timing with the diff. Photo
-
4
Repeat until the program is at least ten times faster than the baseline. Each round is the same: profile, fix one thing, measure. Keep a table of the rounds. Most programs get there in three to five. Take a screenshot of the table. Photo
-
5
Show that the output didn't change. Diff the output of the fast version against the slow version on the same input, byte for byte. A faster wrong answer is a bug. Take a screenshot of the empty diff. Photo
-
6
Write five lines on what was actually slow and what you guessed before profiling. Be honest about the guess, because the gap between the guess and the truth is why you profile. Take a photo or a screenshot of the note. Photo