Transpiled version (5492L) is out of date.
sclass BenchForNSeconds { settable Runnable action; settable double seconds; // how many seconds to run the benchmark volatile bool done; gettable long iterations; long startTime, endTime; gettable new AverageAndMinMax stats; *() {} *(double *seconds, Runnable *action) {} run { startTime = sysNanos(); endTime = lround(startTime+secondsToNanos(seconds)); long time = sysNanos(); while (time < endTime) { action?.run(); long runTook = sysNanos()-time; ++iterations; stats.add(runTook); ping(); time = sysNanos(); } endTime = time; set done; } S formatNanos(double nanos) { ret n2_round(nanos) + " ns"; } toString { ret stats.isEmpty() ? "Not run" : "min/avg/max=" + n2_round(stats.min()) + "/" + n2_round(stats.avg()) + "/" + n2_round(stats.max()) + " ns" + appendRoundBracketed(nRuns((long) stats.n())); } double min() { ret stats.min(); } }
Began life as a copy of #1007922
download show line numbers debug dex old transpilations
Travelled to 4 computer(s): bhatertpkbcr, ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj
No comments. add comment
| Snippet ID: | #1034576 |
| Snippet name: | BenchForNSeconds |
| Eternal ID of this version: | #1034576/15 |
| Text MD5: | e64aceef74f523a4ca2866e8523fe1e2 |
| Author: | stefan |
| Category: | javax |
| Type: | JavaX fragment (include) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2022-02-19 06:46:24 |
| Source code size: | 1030 bytes / 40 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 621 / 805 |
| Version history: | 14 change(s) |
| Referenced in: | [show references] |