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