Libraryless. Click here for Pure Java version (6808L/40K).
1 | sclass CompactQTest { |
2 | // long acc; // This is not the right way |
3 | new AtomicLong atomicAccumulator; // This is the right way |
4 | int n = 100000; |
5 | |
6 | new CompactQ q; |
7 | int qSizeAtEnd; |
8 | long time; |
9 | Scorer scorer; |
10 | |
11 | begin. |
12 | |
13 | long expectedResult = longMul(n, n+1)/2; |
14 | printVars(+n, +expectedResult); |
15 | S name = "Queue " + n; |
16 | time name { |
17 | for (r : inclusiveCountIterator(1, n, i -> r { |
18 | //acc += i; |
19 | add(atomicAccumulator, i); |
20 | })) |
21 | q.add(r); |
22 | qSizeAtEnd = q.size(); |
23 | q.waitUntilDone(); |
24 | //assertEqualsVerbose(scorer, "Non-Atomic", expectedResult, acc); |
25 | assertEqualsVerbose(scorer, "Atomic", expectedResult, atomicAccumulator!); |
26 | } |
27 | time = lastTiming(); |
28 | print(n2(atomicAccumulator) + " // " + n2(qSizeAtEnd)); |
29 | } |
download show line numbers debug dex old transpilations
Travelled to 3 computer(s): bhatertpkbcr, mowyntqkapby, mqqgnosmbjvj
No comments. add comment
Snippet ID: | #1032862 |
Snippet name: | CompactQTest |
Eternal ID of this version: | #1032862/12 |
Text MD5: | a943df97efa9a27c9700fb549c7f3902 |
Transpilation MD5: | 1b2f1d711256bd047d495ca5cdeb4ef2 |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2021-10-07 09:07:29 |
Source code size: | 806 bytes / 29 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 208 / 360 |
Version history: | 11 change(s) |
Referenced in: | [show references] |