% PROF_WAITBAR(N [, DOPROF])
function prof_waitbar(n, doprof)
    if (nargin < 2)
        doprof = false;
    end

    w = waitbar(0);

    if (doprof)
        if (doprof==2)
            profile off
        end
        profile clear
        profile on
    end

    tic;

    for i=1:n
        waitbar(i/n, w);
    end

    t = toc;
    fprintf('%d iterations * %.05fms per iteration = %.03f s total\n', n, t/n, t);

    if (doprof)
        if (doprof==2)
            profile off;
        end
    end

    close(w);
end
