!7 // Now with processor GHz estimate set flag LeanMode. set flag OurSyncCollections. set flag collectionMutex_simple. set flag SymbolAsString. sbool ping() { ret ping_v3(); } static new PingSource myPingSource; static double coresToUse = .5; static double frequency = 100; static new BoolVar on; static volatile long result; static NotTooOften nto = nto(1.0); sclass Counter { new Timestamp start; run { temp tempSetPingSource(myPingSource); loop(); } void loop { long i = 0; var ping = pingSource(); while (true) { if (ping_trueIfSlept(ping)) { result = i; if (nto!) printStats(); } ++i; } } void printStats { Seconds cpu = new(nanosToSeconds(currentThreadTotalCPUNanos())); Seconds clock = new(elapsedSeconds(start)); double cpuRatio = doubleRatio(cpu, clock); double numbersPerSecond = doubleRatio(result, clock!); double npsPerCore = doubleRatio(numbersPerSecond, cpuRatio); double nsPerNumber = doubleRatio(oneBillion(), npsPerCore); double assumedCycles = 2; Freq speedEstimate = new(assumedCycles*npsPerCore); print("I have counted until " + n2(result) + ". pid=" + pid() + ", cpu time: " + cpu + " (clock: " + clock + ", ratio: " + formatDouble1(cpuRatio*100) + "%) - " + n2(lfloor(numbersPerSecond)) + " numbers per second = " + n2(lfloor(npsPerCore)) + " numbers per second per core = " + formatDouble1(nsPerNumber) + " ns per number" + " => Processor speed estimate: " + speedEstimate.format1()); } } p { new Schedule schedule; //enableScaffolding(schedule); schedule.add(0, r { dontprint("on"); myPingSource.action(null); on.set(); }); schedule.add(coresToUse, r { dontprint("off"); on.unset(); myPingSource.action(-> { temp tempPingPrivileged(); on.waitUntilTrue(); true; }); }); schedule.jumpFromTo(1, 0); schedule.speedUp(frequency); //printStruct(schedule); thread "Counting" { new Counter().run(); } schedule.run(); }