performance measurements

Each table row shows performance measurements for this Java program with a particular command-line input value N.

 N  CPU secs Elapsed secs Memory KB Code B ≈ CPU Load
500,0000.250.21236693  9% 73% 10% 43%
5,000,0000.760.6940,352693  49% 37% 4% 23%
50,000,0005.445.34263,428693  69% 28% 1% 6%

Read the ↓ make, command line, and program output logs to see how this program was run.

Read thread-ring benchmark to see what this program should do.

 notes

java version "1.8.0_25"
Java(TM) SE Runtime Environment (build 1.8.0_25-b17)
Java HotSpot(TM) Server VM (build 25.25-b02, mixed mode)

 thread-ring Java #2 program source code

/**
 * The Computer Language Benchmarks Game
 * http://benchmarksgame.alioth.debian.org/
 * contributed by Klaus Friedel
 */

import java.util.*;

public class threadring {

  public static long startTime;
  public static final int THREAD_COUNT = 503;

  // The scheduler for cooperative Multithreading
  static class Scheduler extends Thread{
    private final List<CooperativeThread> threads = Collections.synchronizedList(new ArrayList<CooperativeThread>());
    private int rrIndex = -1;

    public void start(CooperativeThread t){
      threads.add(t);
    }

    public void run() {
      for(;;){ // Scheduler will run foerever
        CooperativeThread nextThread;
        synchronized (threads){
          rrIndex++;
          if(rrIndex >= threads.size()) rrIndex = 0;
          nextThread = threads.get(rrIndex);
        }
        nextThread.handleMessage();
      }
    }
  }

  static abstract class CooperativeThread{
    public abstract void handleMessage();
  }

  static class MessageThread extends CooperativeThread{
      MessageThread nextThread;
      String name;
      Integer msg;

      public MessageThread(MessageThread nextThread, int name) {
        this.name = "" + name;
        this.nextThread = nextThread;
      }

      public void handleMessage(){
        if(msg == null) return;
        if(msg == 0){
          System.out.println(getName());
          System.exit(0);
        }
        nextThread.put(msg - 1);
        msg = null;
      }

      void put(Integer message){
        msg = message;
      }

      String getName() {
        return name;
      }
    }


  public static void main(String args[]) throws Exception{
    int hopCount = Integer.parseInt(args[0]);

    MessageThread thread = null;
    MessageThread last = null;
    for (int i = THREAD_COUNT; i >= 1 ; i--) {
      thread = new MessageThread(thread, i);
      if(i == THREAD_COUNT) last = thread;
    }
    // close the ring:
    last.nextThread = thread;

    Scheduler scheduler = new Scheduler();
    // start all Threads
    MessageThread t = thread;
    do{
      scheduler.start(t);
      t = t.nextThread;
    }while(t != thread);
    scheduler.start();

    // inject message
    thread.put(hopCount);
  }
}

 make, command-line, and program output logs

Wed, 19 Nov 2014 05:30:34 GMT

MAKE:
mv threadring.java-2.java threadring.java
/usr/local/src/jdk1.8.0_25/bin/javac threadring.java
0.75s to complete and log all make actions

COMMAND LINE:
/usr/local/src/jdk1.8.0_25/bin/java  -server -XX:+TieredCompilation -XX:+AggressiveOpts threadring 50000000

PROGRAM OUTPUT:
292

Revised BSD license

  Home   Conclusions   License   Play