Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

25
LINES

< > BotCompany Repo | #1009317 - benchForNSeconds2 [dev.]

JavaX fragment (include)

// 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;
}

Author comment

Began life as a copy of #1007922

download  show line numbers  debug dex   

Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, 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: 325 / 335
Version history: 3 change(s)
Referenced in: [show references]

Formerly at http://tinybrain.de/1009317 & http://1009317.tinybrain.de