By Victor J. Duvanenko, April 16, 2012 Algorithms for swapping blocks of data appear simple, but vary widely in their performance profiles. Choosing the right one can be crucial to good performance. Swapping two elements within an array quickly is simple, requiring a single temporary storage element. template < class Item > inline void exchange( Item& A, Item& B ) { Item t = A; A = B; B = t; } Swapping two non-overlapping subarrays of the same size is also simple. Figure 1. In Figure 1, the red subarray, containing two elements, is swapped with the blue subarray, also containing two elements.
Read full article from Benchmarking Block-Swapping Algorithms | Dr Dobb's
No comments:
Post a Comment