// returns result of function static <A> A benchForNSeconds2(double n, S desc default str(f), IF0<A> 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; }
Began life as a copy of #1007922
download show line numbers debug dex old transpilations
Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv
No comments. add comment
Snippet ID: | #1009317 |
Snippet name: | benchForNSeconds2 [dev.] |
Eternal ID of this version: | #1009317/4 |
Text MD5: | af307d490a9f0ce4aed121ca44004e87 |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2020-07-24 19:51:56 |
Source code size: | 807 bytes / 25 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 524 / 555 |
Version history: | 3 change(s) |
Referenced in: | [show references] |