June 2019
Intermediate to advanced
218 pages
5h 19m
English
Given what we discussed in the previous section about the benefits of preallocating output, it should come as no surprise that many base library functions in Julia have mutating counterparts that modify their arguments, rather than allocating a new output structure.
For example, the sort base library function that sorts an array, allocates a new array of the same size as its input to hold its output—the sorted array. On the other hand, sort! makes an in-place sorting operation, in which the input array is itself sorted as follows:
julia> @btime sort(a); 16.740 μs (1 allocation: 7.94 KiB)julia> @btime sort!(a); 5.757 μs (0 allocations: 0 bytes)
In this case, not only is the performance difference significant, but the allocating ...
Read now
Unlock full access