set verbose off clear scalar ROW = 10000 scalar COL = 20 scalar BLOCK_size = 2000 scalar BLOCK_start = 115 scalar LOOP = 600 matrix A = mnormal(ROW, COL) matrix B = zeros(ROW, COL) set stopwatch loop LOOP --quiet loop i=1..BLOCK_size --quiet loop j=1..COL --quiet B[BLOCK_start - 1 + i, j] = A[BLOCK_start - 1 + i, j] endloop endloop endloop t1 = $stopwatch n_add_sub = BLOCK_size * COL * 2 * 2 printf "loop 1: %.4f (add/sub = %d)\n", t1, n_add_sub set stopwatch loop LOOP --quiet loop i=0..BLOCK_size-1 --quiet loop j=1..COL --quiet B[BLOCK_start + i, j] = A[BLOCK_start + i, j] endloop endloop endloop t2 = $stopwatch n_add_sub = BLOCK_size * COL * 2 * 1 printf "loop 2: %.4f (add/sub = %d)\n", t2, n_add_sub loop LOOP --quiet loop i=1..BLOCK_size --quiet loop j=1..COL --quiet k = BLOCK_start - 1 + i B[k,j] = A[k,j] endloop endloop endloop t3 = $stopwatch n_add_sub = BLOCK_size * COL * 2 printf "loop 3: %.4f (add/sub = %d)\n", t3, n_add_sub set stopwatch loop LOOP --quiet loop i=0..BLOCK_size-1 --quiet loop j=1..COL --quiet k = BLOCK_start + i B[k,j] = A[k,j] endloop endloop endloop t4 = $stopwatch n_add_sub = 1 + BLOCK_size * COL printf "loop 4: %.4f (add/sub = %d)\n", t4, n_add_sub set stopwatch loop LOOP --quiet loop i=0..BLOCK_size-1 --quiet k = BLOCK_start + i loop j=1..COL --quiet B[k,j] = A[k,j] endloop endloop endloop t4a = $stopwatch n_add_sub = 1 + BLOCK_size printf "loop 4a: %.4f (add/sub = %d)\n", t4a, n_add_sub loop LOOP --quiet loop i=BLOCK_start..BLOCK_start-1+BLOCK_size --quiet loop j=1..COL --quiet B[i,j] = A[i,j] endloop endloop endloop t5 = $stopwatch n_add_sub = 2 printf "loop 5: %.4f (add/sub = %d)\n", t5, n_add_sub loop LOOP --quiet imin = BLOCK_start imax = BLOCK_start-1+BLOCK_size loop j=1..COL --quiet B[imin:imax, j] = A[imin:imax, j] endloop endloop t6 = $stopwatch n_add_sub = 2 printf "loop 6: %.4f (add/sub = %d; column chunks)\n", t6, n_add_sub