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

65
LINES

< > BotCompany Repo | #1002402 // Timing Bot

JavaX source code [tags: use-pretranspiled] - run with: x30.jar

Libraryless. Click here for Pure Java version (1549L/10K/35K).

!752

// Our version of the #1002317's Bot class, just for querying.
// Thanks to the magic of restructure(), it will be filled
// automagically.
static class Bot {
  S id; // always formatted
  boolean enabled, always;
}

answer {
  if (swic(s, "timing ")) {
    S input = dropPrefix("timing ", s);
    O dispatcher = call(getMainBot(), "getDispatcher");
    L bots = cast call(dispatcher, "getSubBots");
    new L<S> l;
    long startTime = now();
    for (int i = 0; i < l(bots); i++) {
      Bot bot = null;
      time {}
      try {
        bot = (Bot) restructure(bots.get(i));
        if (!bot.enabled) {
          l.add(bot.id + ": Not enabled");
          continue;
        }
        if (sameSnippetID(bot.id, getProgramID()))
          continue; // skip myself
        Class c = cast call(dispatcher, "getClassOfSubBot", bot.id);
        if (c != null) {
          S a = null;
          time {
            a = callStaticAnswerMethod(c, input);
          }
          if (empty(a))
            l.add(bot.id + ": " + lastTiming() + " ms - \"\"");
          else {
            l.add(bot.id + ": " + lastTiming() + " ms - RETURN " + quote(a));
            informAlwaysBots(dispatcher, subList(bots, i+1), input, l);
            break;
          }
        }
      } catch(Exception e) { l.add(exceptionToUser(e)); }
    }

    l.add("Total: " + (now()-startTime) + " ms");
    ret "```" + fromLines(l) + "```";
  }
}

static void informAlwaysBots(O dispatcher, L<Bot> bots, S s, L<S> l) {
  for (O _bot : bots) {
    Bot bot = (Bot) restructure(_bot);
    if (bot.always) pcall { // TODO: print exception
      Class c = cast call(dispatcher, "getClassOfSubBot", bot.id);
      if (c != null) {
        S a = null;
        time {
          a = callStaticAnswerMethod(c, s);
        }
        l.add(bot.id + " (always): " + lastTiming() + " ms - " + quote(a));
      }
    }
  }
}

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1002402
Snippet name: Timing Bot
Eternal ID of this version: #1002402/1
Text MD5: 13ba340c7b61a6eb0e1232b895eaf913
Transpilation MD5: bd863038e47c5030607adb4e8d8e5f20
Author: stefan
Category: javax
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-04-14 19:27:00
Source code size: 1947 bytes / 65 lines
Pitched / IR pitched: No / No
Views / Downloads: 825 / 1568
Referenced in: [show references]