Nice TWiki > Doc > BenchIntermediateExample ( vs. r1.1) TWiki webs:
Dev | Doc | Main | TWiki | Sandbox
Doc . { Changes | Index | Search | Go }
 <<O>>  Difference Topic BenchIntermediateExample (r1.1 - 02 Sep 2003 - DuncanLissett)
Added:
>
>

%META:TOPICINFO{author="DuncanLissett" date="1062534327" format="1.0" version="1.1"}% %META:TOPICPARENT{name="CodeExamples"}%

package bench;

/**
 *      Martin Richards developed Bench as a test of
 *      systems programming languages.
 *
 *      http://www.cl.cam.ac.uk/users/mr/Bench.html
 *
 *      In this interpretation of the test, each scheduler
 *      function is associated with it's datatypes in a class,
 *      and works directly on those values in the Tcb without
 *      restoring them to registers.
 *     
 *      http://www.lissett.com/ben/exp/bench1.htm
 *
 *      For Count = 10,000 the correct result is
 *      QueueCount = 23,246 and HoldCount = 9,297.
 *
 *      For Count = 1,000,000 the correct result is
 *      QueueCount = 2,326,410 and HoldCount = 930,563.
 *
 */

let boolean traceOn = false;

void main(String[] args) {
   let count = toSingleInt(args);
   let startTicks = System.currentTimeMillis();
   
   let s = new Scheduler();
   var wkq = NoPacket;

   s.addIdleTask(id: Idle, priority: 0, wkq: NoPacket, count);

   wkq = new Packet(link: NoPacket, id: Worker, kind: Work);
   wkq = new Packet(link: wkq, id: Worker, kind: Work);
   s.addWorkerTask(id: Worker, priority: 1000, wkq);

   wkq = new Packet(link: NoPacket, id: DeviceA, kind: Device);
   wkq = new Packet(link: wkq, id: DeviceA, kind: Device);
   wkq = new Packet(link: wkq, id: DeviceA, kind: Device);
   s.addHandlerTask(id: HandlerA, priority: 2000, wkq);

   wkq = new Packet(link: NoPacket, id: DeviceB, kind: Device);
   wkq = new Packet(link: wkq, id: DeviceB, kind: Device);
   wkq = new Packet(link: wkq, id: DeviceB, kind: Device);
   s.addHandlerTask(id: HandlerB, priority: 3000, wkq);

   s.addDeviceTask(id: DeviceA, priority: 4000, wkq: NoPacket);
   s.addDeviceTask(id: DeviceB, priority: 5000, wkq: NoPacket);

   s.schedule();

   println("QueueCount = " + s.queueCount);
   println("HoldCount = " + s.holdCount);
   println(System.currentTimeMillis() - startTicks + " milliseconds");
}


var int layout = 0;

void trace(char aChar){
   --layout;
   if (layout <= 0){
      println("");
      layout = 50;
   }
   print(aChar);
}


int toSingleInt(String[] s){
   try { return Integer.parseInt(s[0]); }
   catch (Exception e){ return 10000; } }
-- DuncanLissett - 02 Sep 2003

Topic BenchIntermediateExample . { View | Diffs | r1.1 | More }
Revision -
Revision r1.1 - 02 Sep 2003 - 20:25 GMT - DuncanLissett
Copyright © 1999-2003 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback.