// returns result of function
static A benchForNSeconds2(double n, S desc default str(f), IF0 f) {
benchForNSeconds2(n, r { f! });
ret f!;
}
// returns minimal time needed
// TODO: sub-second duration
static long benchForNSeconds2(S desc, Runnable r, double n, int innerRepetitions) {
long start = sysNow(), min = -1, print = sysNow();
int seconds = 1;
while (seconds <= n) {
long time = sysNow();
for (int i = 0; i < innerRepetitions; i++)
r.run();
long now = sysNow();
time = now-time;
min = min < 0 ? time : min(min, time);
if (now >= start+seconds*1000) {
printAndSetConsoleTitle(min + " ms: " + desc + " (" + seconds + "/" + (n*(long) innerRepetitions) + " s, last=" + time + " ms)");
++seconds;
}
}
ret min;
}