PageRenderTime 67ms CodeModel.GetById 62ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/bench/kilim/bench/Jetlang.java

http://github.com/kilim/kilim
Java | 50 lines | 32 code | 8 blank | 10 comment | 4 complexity | e2454ba8e7d5e92c0f35795c2be24f4a MD5 | raw file
 1/* Copyright (c) 2006, Sriram Srinivasan
 2 *
 3 * You may distribute this software under the terms of the license 
 4 * specified in the file "License"
 5 */
 6
 7package kilim.bench;
 8import kilim.Mailbox;
 9import kilim.Pausable;
10import kilim.Task;
11/**
12 * Compare this to Jetlang's PerfMain tests
13 * See http://code.google.com/p/jetlang/
14 */
15public class Jetlang extends Task {
16    
17    /* limit number  of msgs in mailbox */
18    static Mailbox<Integer> mb = new Mailbox<Integer>(1000,1000);
19    final static int max = 5000000;
20    
21    public static void main(String args[]) throws Exception {
22        Stopwatch s = new Stopwatch();
23        s.tick();
24
25        Task t = new Jetlang().start();
26        new Publisher().start();
27        t.joinb(); // wait for receiver to finish
28        
29        s.tickPrint(max+1); // same number of iterations as jetlang's tests.
30        Task.idledown();
31    }
32
33    public void execute() throws Pausable {
34        while (true) {
35            int i = mb.get();
36            if (i == max) {
37                break;
38            }
39        }
40    }
41    
42    static class Publisher extends Task {
43        public void execute() throws Pausable {
44            for (int i = 0; i <= max; i++) {
45                mb.put(i);
46          }
47        }
48    }
49}
50