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