Libraryless. Click here for Pure Java version (1549L/10K/35K).
1 | !752 |
2 | |
3 | // Our version of the #1002317's Bot class, just for querying. |
4 | // Thanks to the magic of restructure(), it will be filled |
5 | // automagically. |
6 | static class Bot {
|
7 | S id; // always formatted |
8 | boolean enabled, always; |
9 | } |
10 | |
11 | answer {
|
12 | if (swic(s, "timing ")) {
|
13 | S input = dropPrefix("timing ", s);
|
14 | O dispatcher = call(getMainBot(), "getDispatcher"); |
15 | L bots = cast call(dispatcher, "getSubBots"); |
16 | new L<S> l; |
17 | long startTime = now(); |
18 | for (int i = 0; i < l(bots); i++) {
|
19 | Bot bot = null; |
20 | time {}
|
21 | try {
|
22 | bot = (Bot) restructure(bots.get(i)); |
23 | if (!bot.enabled) {
|
24 | l.add(bot.id + ": Not enabled"); |
25 | continue; |
26 | } |
27 | if (sameSnippetID(bot.id, getProgramID())) |
28 | continue; // skip myself |
29 | Class c = cast call(dispatcher, "getClassOfSubBot", bot.id); |
30 | if (c != null) {
|
31 | S a = null; |
32 | time {
|
33 | a = callStaticAnswerMethod(c, input); |
34 | } |
35 | if (empty(a)) |
36 | l.add(bot.id + ": " + lastTiming() + " ms - \"\""); |
37 | else {
|
38 | l.add(bot.id + ": " + lastTiming() + " ms - RETURN " + quote(a)); |
39 | informAlwaysBots(dispatcher, subList(bots, i+1), input, l); |
40 | break; |
41 | } |
42 | } |
43 | } catch(Exception e) { l.add(exceptionToUser(e)); }
|
44 | } |
45 | |
46 | l.add("Total: " + (now()-startTime) + " ms");
|
47 | ret "```" + fromLines(l) + "```"; |
48 | } |
49 | } |
50 | |
51 | static void informAlwaysBots(O dispatcher, L<Bot> bots, S s, L<S> l) {
|
52 | for (O _bot : bots) {
|
53 | Bot bot = (Bot) restructure(_bot); |
54 | if (bot.always) pcall { // TODO: print exception
|
55 | Class c = cast call(dispatcher, "getClassOfSubBot", bot.id); |
56 | if (c != null) {
|
57 | S a = null; |
58 | time {
|
59 | a = callStaticAnswerMethod(c, s); |
60 | } |
61 | l.add(bot.id + " (always): " + lastTiming() + " ms - " + quote(a)); |
62 | } |
63 | } |
64 | } |
65 | } |
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: | 1076 / 1890 |
| Referenced in: | [show references] |