/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. package kilim.bench;
  7. import kilim.Mailbox;
  8. import kilim.Pausable;
  9. import kilim.Task;
  10. /**
  11. * Compare this to Jetlang's PerfMain tests
  12. * See http://code.google.com/p/jetlang/
  13. */
  14. public class Jetlang extends Task {
  15. /* limit number of msgs in mailbox */
  16. static Mailbox<Integer> mb = new Mailbox<Integer>(1000,1000);
  17. final static int max = 5000000;
  18. public static void main(String args[]) throws Exception {
  19. Stopwatch s = new Stopwatch();
  20. s.tick();
  21. Task t = new Jetlang().start();
  22. new Publisher().start();
  23. t.joinb(); // wait for receiver to finish
  24. s.tickPrint(max+1); // same number of iterations as jetlang's tests.
  25. Task.idledown();
  26. }
  27. public void execute() throws Pausable {
  28. while (true) {
  29. int i = mb.get();
  30. if (i == max) {
  31. break;
  32. }
  33. }
  34. }
  35. static class Publisher extends Task {
  36. public void execute() throws Pausable {
  37. for (int i = 0; i <= max; i++) {
  38. mb.put(i);
  39. }
  40. }
  41. }
  42. }