cmd = 'find (x)';
fmt = '%.2g, %.2g';
o_full  = speed(cmd,'x = full(diag(ones(n,1)));',[1e2 1e4]);
o_diagM = speed(cmd,'x = diag(ones(n,1));',[1e2 1e4]);
o_diag  = speed(cmd,'x = ones(n,1);',[1e2 1e4]);
fprintf ("Order, time per operation (ones)\n");
fprintf (sprintf("Full: %s\n", fmt), o_full.p, o_full.a)
fprintf (sprintf("Diag: %s\n", fmt), o_diagM.p, o_diagM.a)
fprintf (sprintf("Opt: %s\n", fmt), o_diag.p, o_diag.a)

o_full  = speed(cmd,'x = full(diag(rand(n,1) > 0.3));',[1e2 1e4]);
o_diagM = speed(cmd,'x = diag(rand(n,1) > 0.3);',[1e2 1e4]);
o_diag  = speed(cmd,'x = rand(n,1) > 0.3;',[1e2 1e4]);
fprintf ("\nOrder, time per operation (bool)\n");
fprintf (sprintf("Full: %s\n", fmt), o_full.p, o_full.a)
fprintf (sprintf("Diag: %s\n", fmt), o_diagM.p, o_diagM.a)
fprintf (sprintf("Opt: %s\n", fmt), o_diag.p, o_diag.a)
