IDL supplies a number of built-in functions and procedures to perform common operations. These system-supplied functions have been carefully optimized and are almost always much faster than writing the equivalent operation in IDL with loops and subscripting.
A common operation is to find the sum of the elements in an array or subarray. The TOTAL function directly and efficiently evaluates this sum at least 10 times faster than directly coding the sum.
;Slow way: Initialize SUM and sum each element. sum = 0. & FOR I = J, K DO sum = sum + array[I] ;Efficient, simple way. sum = TOTAL(array[J:K])
Similar savings result when finding the minimum and maximum elements in an array (MIN and MAX functions), sorting (SORT function), finding zero or nonzero elements (WHERE function), etc.