Transpiled version (2749L) is out of date.
1 | // returns result of function |
2 | static <A> A benchForNSeconds(double n, S desc default str(f), IF0<A> f) { |
3 | benchForNSeconds(r { f! }, n); |
4 | ret f!; |
5 | } |
6 | |
7 | // returns minimal time needed |
8 | static long benchForNSeconds(S desc default str(r), Runnable r, double n) { |
9 | long start = sysNow(), min = -1, print = sysNow(); |
10 | int seconds = 1; |
11 | long count = 0, sum = 0; |
12 | while (seconds <= n) { |
13 | long time = nanos(); |
14 | r.run(); |
15 | ++count; |
16 | time = nanos()-time; |
17 | min = min < 0 ? time : min(min, time); |
18 | sum += time; |
19 | double avg = doubleRatio(sum, count); |
20 | if (sysNow() >= start+seconds*1000) { |
21 | printAndSetConsoleTitleIfMain( |
22 | "n=" + n2(count) + ", avg=" + formatDouble(nanosToMS(avg), 3) + " ms, " + |
23 | "min=" + formatDouble(nanosToMS(min), 3) + " ms: " + |
24 | desc + " (" + seconds + "/" + n + " s, last=" + formatDouble(nanosToMS(time), 3) + " ms, " + n2(count) + "/s)"); |
25 | ++seconds; |
26 | count = sum = 0; |
27 | } |
28 | } |
29 | ret min; |
30 | } |
Began life as a copy of #1006403
download show line numbers debug dex old transpilations
Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mowyntqkapby, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv
No comments. add comment
Snippet ID: | #1007922 |
Snippet name: | benchForNSeconds |
Eternal ID of this version: | #1007922/10 |
Text MD5: | b65e8c8c550fcd414aa3024263f78425 |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-06-16 21:54:53 |
Source code size: | 994 bytes / 30 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 589 / 755 |
Version history: | 9 change(s) |
Referenced in: | [show references] |