March 2019
Intermediate to advanced
208 pages
5h 11m
English
You may have noticed this line:
| | Js.String.slice(~from= 1, ~to_= (len - 2), s) |
and thought, “Holy crapoley. He’s allocating a new string every time he does a recursive call. That must be slow as a turtle trudging through molasses.” Let’s be clear—it’s the reallocation that is expensive, not the fact that we’re using recursion. A while loop using the same approach would be doing the reallocation as well. So, even though performance of this particular example isn’t a major issue and CPU time is cheap, let’s find out how long it takes to determine if a string of 50,000 repetitions of the letter a is a palindrome or not (it is). Writing that code is as good an excuse as any to give more examples of ...
Read now
Unlock full access