![]() ![]() ![]() In MATLAB, it is easy to inadvertently make copies of your data. For other column sizes, code can run up to an order of magnitude more slowly. The operation is most efficient for a column size equal to 1, a 1-D vector. Figure 3 shows the time taken per element on the two machines to perform element-wise multiplication of a 10k element row vector by a matrix of varying column size. For example, column size affects memory access time when you operate on row vectors because it determines the stride, or step through memory. If the algorithm permits, you can also maximize cache efficiency by using the single index method, x(k), instead of x(r,c).Ĭache effects are data-size- and machine-dependent, making it difficult to predict performance. Because MATLAB stores matrix columns in monotonically increasing memory locations, processing data column-wise results in maximum cache efficiency.Ĭode segment 2 is faster because it traverses the elements of the 2-D array by going down the columns in the inner loop. ![]() ![]() Your code achieves maximum cache efficiency when it traverses monotonically increasing memory locations. Why Code Segment 2 is Faster Modern CPUs use a fast cache to reduce the average time taken to access main memory. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |