January 2020
Intermediate to advanced
532 pages
13h 31m
English
A barrier function involves refactoring a piece of logic from an existing function into a new, separate function. When it's done, all data required by the new function will be passed as function arguments. Continuing with the preceding example, we can factor out the logic that calculates the doubled sum of data as follows:
function double_sum(data) total = 0 for v in data total += 2 * v end return totalend
Then, we just modify the original function to make use of this function:
function double_sum_of_random_data(n) data = random_data(n) return double_sum(data)end
Does it really improve performance? Let's run the test:
It turns out to have a huge difference for the Float64 case—the elapsed time went from 347 to ...
Read now
Unlock full access