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.19?543  20% 26% 17% 79%
5,000,0000.330.27428543  15% 37% 26% 61%
50,000,0001.020.95153,228543  4% 83% 15% 8%

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"
Java(TM) SE Runtime Environment (build 1.8.0-b132)
Java HotSpot(TM) 64-Bit Server VM (build 25.0-b70, mixed mode)

 thread-ring Java #6 program source code

/**
 * The Computer Language Benchmarks Game
 * http://benchmarksgame.alioth.debian.org/
 *
 * contributed by Fabien Le Floc'h
 *
 * This implementation cheats by adapting closely to the benchmark specifications. 
 * We use only 1 thread to process messages, we don't use a blocking queue but 
 * instead a linked list. The Nodes don't map directly to a thread, even though
 * they are processed in a different thread (the consumer). This is probably this kind
 * of scheme that more advanced languages like Haskell do behind the scenes.
 * 
 * I say it is a bit cheating because we don't use here a concurrent queue, because 
 * we know everything is processed in 1 thread: the consumer except the first message.
 */


import java.util.LinkedList;
import java.util.Queue;


public class threadring {
    public static void main(String[] args) {
        Node[] ring = new Node[503];
        for (int i=0; i<ring.length; i++) {
            ring[i] = new Node(i+1);
        }
        for (int i=0; i<ring.length; i++) {
            int nextIndex = (ring[i].label % ring.length);
            ring[i].next = ring[nextIndex];            
        }
        int nHops = Integer.parseInt(args[0]);
        new Thread(new Consumer()).start();
        ring[0].sendMessage(nHops);
    }

    private static Queue<Node> q = new LinkedList<Node>();

    static class Consumer implements Runnable {

        public void run() {
            while (true) {
                try {
                    Node node;
                    node = q.poll();
                    if (node == null) {
                        //ignore, wait for some element
                        Thread.sleep(100);
                    } else {
                        node.run();
                    } 
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }
    static class Node implements Runnable {
        private final int label;
        private Node next;
        private int message;

        public Node(int label) {
            this.label = label;
        }

        public void sendMessage(int message) {
            this.message=message;
            q.add(this);            
        }

        public void run() {
            //                System.out.println("after lock");
            if (message == 0) {
                System.out.println(label);
                System.exit(0);
            } else {
                next.sendMessage(message - 1);
            }
        }
    }
}

 make, command-line, and program output logs

Tue, 18 Mar 2014 22:50:47 GMT

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

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

PROGRAM OUTPUT:
292

Revised BSD license

  Home   Conclusions   License   Play