% A long chain of elementwise math on 4 million elements, fused into ONE % GPU kernel per source line and replayed 200 times. % Paste this whole script into MATLAB to compare timings. n = 4000000; x = rand(n, 1); y = zeros(n, 1); tic; for k = 1:200 y = y + 0.1*sin(x + k) .* exp(-x) + x.^2; end t = toc; fprintf('%.0f million element-updates/sec\n', 200*n/1e6/t); fprintf('checksum %.4f (rand differs from MATLAB; expect ~equal, not equal)\n', mean(y));