clear;

k = 800000;
r = 5;
n = 6;
q = 4;

A = rand(k*r, n);
B = rand(k*n, q);

C1 = zeros(k*r, q);

tic;
for i = 1 : k
    ra = (i-1)*r + (1:r);
    rb = (i-1)*n + (1:n);
    C1(ra, :) = A(ra, :) * B(rb, :);
end
t_loop = toc;

tic;
C2 = multi_block_product(A, B);
t_block = toc;

max(max(abs(C1-C2)))

isequal(C1, C2)