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

29
LINES

< > BotCompany Repo | #1032862 // CompactQTest

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (6808L/40K).

sclass CompactQTest {
  // long acc;                       // This is not the right way
  new AtomicLong atomicAccumulator;  // This is the right way
  int n = 100000;
  
  new CompactQ q;
  int qSizeAtEnd;
  long time;
  Scorer scorer;
  
  begin.

  long expectedResult = longMul(n, n+1)/2;
  printVars(+n, +expectedResult);
  S name = "Queue " + n;
  time name {
    for (r : inclusiveCountIterator(1, n, i -> r {
      //acc += i; 
      add(atomicAccumulator, i);
    }))
      q.add(r);
    qSizeAtEnd = q.size();
    q.waitUntilDone();
    //assertEqualsVerbose(scorer, "Non-Atomic", expectedResult, acc);
    assertEqualsVerbose(scorer, "Atomic", expectedResult, atomicAccumulator!);
  }
  time = lastTiming();
  print(n2(atomicAccumulator) + " // " + n2(qSizeAtEnd));
}

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: 207 / 357
Version history: 11 change(s)
Referenced in: #1034167 - Standard Classes + Interfaces (LIVE, continuation of #1003674)