performance measurements

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

 N  CPU secs Elapsed secs Memory KB Code B ≈ CPU Load
500,00010.557.9223,800591  29% 32% 33% 28%
5,000,00082.4860.8123,744591  34% 31% 29% 29%
50,000,000785.68551.6023,628591  34% 33% 32% 30%

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

Mono JIT compiler version 3.10.1 (master/9fd3c7a Thu Sep 11 15:32:17 PDT 2014)
LLVM: yes(3.4svn-mono-mono/e656cac)
GC: sgen

 thread-ring C# Mono #2 program source code

/* The Computer Language Benchmarks Game

   http://benchmarksgame.alioth.debian.org/

   contributed by Isaac Gouy

   modified by Konstantin Safonov

 */

using System;
using System.Diagnostics;
using System.Linq;
using System.Threading;

internal class NamedThread {
    private readonly int name;
    private readonly ManualResetEventSlim signal = new ManualResetEventSlim(false);
    private int token;

    internal NamedThread( int name ) {
        this.name = name;
    }

    internal NamedThread NextThread() {
        return ThreadRing.threadRing[ name % ThreadRing.numberOfThreads ];
    }

    internal void Run() {
        while ( TokenNotDone() )
            NextThread().TakeToken( token - 1 );

        if ( token == 0 ) Console.WriteLine( name );
        NextThread().TakeToken( -1 );
    }

    internal void TakeToken( int x ) {
        token = x;
        signal.Set();
    }

    private bool TokenNotDone() {
        signal.Wait();
        signal.Reset();
        return token > 0;
    }
}

public class ThreadRing {
    internal const int numberOfThreads = 503;
    internal static NamedThread[] threadRing = new NamedThread[503];

    private static void Main( String[] args ) {
        Main2( args );
    }

    public static void Main2( string[] args ) {
        for ( var i = 0; i < numberOfThreads; i++ ) threadRing[ i ] = new NamedThread( i + 1 );
        var thrs = threadRing.Select( a => new Thread( a.Run ) ).ToArray();
        foreach ( var thread in thrs ) thread.Start(); 
        var cnt = args.Length > 0 ? int.Parse( args[ 0 ] ) : 50000000;
        threadRing[ 0 ].TakeToken( cnt );
        foreach ( var thread in thrs ) thread.Join();
    }
}

 make, command-line, and program output logs

Fri, 12 Sep 2014 09:50:14 GMT

MAKE:
mv threadring.csharp-2.csharp threadring.csharp-2.cs
/usr/local/bin/mcs  -optimize+ -platform:x86 -out:threadring.csharp-2.csharp_run threadring.csharp-2.cs
rm threadring.csharp-2.cs
0.25s to complete and log all make actions

COMMAND LINE:
/usr/local/bin/mono --llvm threadring.csharp-2.csharp_run 50000000

PROGRAM OUTPUT:
292

Revised BSD license

  Home   Conclusions   License   Play