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

61
LINES

< > BotCompany Repo | #1033318 // Count in 50% of a core v1

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

Download Jar. Libraryless. Click here for Pure Java version (5956L/33K).

1  
!7
2  
3  
set flag LeanMode. set flag OurSyncCollections. set flag collectionMutex_simple.
4  
//do not include class Symbol.
5  
set flag SymbolAsString.
6  
//do not include function getOpt.
7  
8  
sbool ping() { ret ping_v3(); }
9  
10  
static new PingSource myPingSource;
11  
12  
static double coresToUse = .5;
13  
static double frequency = 100;
14  
static new BoolVar on;
15  
static volatile long result;
16  
static NotTooOften nto = nto(1.0);
17  
18  
p/*-exp*/ { // exp for "experiment" automatically reloads on updates
19  
  new Schedule<Runnable> schedule;
20  
  //enableScaffolding(schedule);
21  
  schedule.add(0, r {
22  
    dontprint("on");
23  
    myPingSource.action(null);
24  
    on.set();
25  
  });
26  
  schedule.add(coresToUse, r {
27  
    dontprint("off");
28  
    on.unset();
29  
    myPingSource.action(-> {
30  
      temp tempPingPrivileged();
31  
      on.waitUntilTrue();
32  
      true;
33  
    });
34  
  });
35  
  schedule.jumpFromTo(1, 0);
36  
  schedule.speedUp(frequency);
37  
  //printStruct(schedule);
38  
  thread "Counting" {
39  
    temp tempSetPingSource(myPingSource);
40  
    new Timestamp start;
41  
    
42  
    long i = 0;
43  
    var ping = pingSource();
44  
    while (true) {
45  
      if (ping_trueIfSlept(ping)) {
46  
        result = i;
47  
        if (nto!) {
48  
          Seconds cpu = new(nanosToSeconds(currentThreadTotalCPUNanos()));
49  
          Seconds clock = new(elapsedSeconds(start));
50  
          double numbersPerSecond = doubleRatio(i, clock!);
51  
          print("I have counted until " + n2(i) + ". pid=" + pid() + ", cpu time: " + cpu + " (clock: " + clock
52  
            + ", ratio: " + formatDouble1(doublePercentRatio(cpu, clock)) + "%) - "
53  
            + n2(ifloor(numbersPerSecond)) + " numbers per second");
54  
        }
55  
      }
56  
      
57  
      ++i;
58  
    }
59  
  }
60  
  schedule.run();
61  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 2 computer(s): bhatertpkbcr, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1033318
Snippet name: Count in 50% of a core v1
Eternal ID of this version: #1033318/50
Text MD5: 8a990009982d37c85a5c85afa95c2063
Transpilation MD5: 1689f87ad8e7fc11e38b108ff49063e1
Author: stefan
Category: javax / gazelle v
Type: JavaX source code (desktop)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-10-24 18:52:37
Source code size: 1710 bytes / 61 lines
Pitched / IR pitched: No / No
Views / Downloads: 255 / 1069
Version history: 49 change(s)
Referenced in: [show references]