Libraryless. Click here for Pure Java version (1627L/10K/34K).
1 | !752 |
2 | |
3 | static class Event { |
4 | long startTime, duration; |
5 | S question, answer; |
6 | S botID; |
7 | } |
8 | |
9 | static PersistentLog<Event> data; |
10 | |
11 | p { |
12 | data = new PersistentLog("data.log"); |
13 | } |
14 | |
15 | synchronized answer { |
16 | if "avg processing time" { |
17 | if (empty(data)) ret "No data yet"; |
18 | long avg = round(getAverage(data, "duration")); |
19 | ret avg + " ms per question (" + l(data) + " requests counted)"; |
20 | } |
21 | |
22 | if (match("clear avg processing time", s) && getUserName() != null) { |
23 | data.clear(); |
24 | ret "OK, log cleared."; |
25 | } |
26 | } |
27 | |
28 | static synchronized S answerPriv(S s) { |
29 | new Matches m; |
30 | if (match("log timing *", s, m)) { |
31 | new Event e; |
32 | copyFields(safeUnstructure(m.unq(0)), e); |
33 | |
34 | // mandatory fields |
35 | assertTrue(e.startTime != 0); |
36 | assertTrue(e.duration >= 0); |
37 | assertTrue(!empty(e.question)); |
38 | |
39 | data.add(e); |
40 | ret "OK, logged as item " + l(data); |
41 | } |
42 | ret null; |
43 | } |
download show line numbers debug dex old transpilations
Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1002174 |
Snippet name: | avg processing time bot |
Eternal ID of this version: | #1002174/1 |
Text MD5: | dbd75303862a6d8b663f2e09b2e5d6f6 |
Transpilation MD5: | 061ffe3f45e9c11725cc1b1a4ef4c740 |
Author: | stefan |
Category: | javax |
Type: | JavaX source code |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2016-01-19 18:02:41 |
Source code size: | 930 bytes / 43 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 670 / 1768 |
Referenced in: | [show references] |