Click here to Skip to main content
11,921,889 members (65,054 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


2 bookmarked

Roselyn CTP vs. Microsoft.CSharp (C# native compiler)

, 4 Sep 2012 CPOL
Rate this:
Please Sign up or sign in to vote.
Comparison between the new Roselyn CTP compiler from Microsoft and the native C# compiler which is integrated into .NET.

Here is a small comparison between the new Roselyn CTP compiler from Microsoft ( and the native C# compiler which is integrated into .NET.

Here is the code used for testing compilation between the "two" compilers:

static class Program
    static void Main()
        int pass = 50;
        List<long> rList = new List<long>();
        List<long> oList = new List<long>();
        for (int i = 1; i < pass; i++)
            long roselynVal = TestRoselyn();
            long oldVal = TestOld();
            Console.WriteLine("Roselyn Pass " + i + ":  " + roselynVal.ToString() + 
                     "\t\tOld Microsoft compiler Pass " + i + ":  " + oldVal.ToString());
        var rosleynAvg = rList.Average();
        var oldAvg = oList.Average();
        //var rAvg = from r in rList
        Console.WriteLine("Roselyn average ms:\t" + rosleynAvg);
        Console.WriteLine("Microsoft old compiler average ms:\t" + oldAvg);
    /// <summary>
    /// Test roselyn
    /// </summary>
    /// <returns></returns>
    private static long TestRoselyn()
        //Crate stopwatch and evaluate script using Roselyn
        Stopwatch sw = new Stopwatch();
        var engine = new ScriptEngine();
        var result = engine.Execute<bool>("var x = 10; x == 10");
        return sw.ElapsedMilliseconds;
    /// <summary>
    /// Test old one
    /// </summary>
    /// <returns></returns>
    private static long TestOld()
        Stopwatch sw2 = new Stopwatch();
        Microsoft.CSharp.CSharpCodeProvider cp = new CSharpCodeProvider();
        CompilerParameters cparam = new CompilerParameters { GenerateInMemory = true };
        CompilerResults cr = cp.CompileAssemblyFromSource(cparam,
           "namespace RoselynTemplate { class Main { public bool " + 
           "GetSmt() { var x = 10; return x == 10; } }}");
        var instance = cr.CompiledAssembly.CreateInstance("RoselynTemplate.Main");
        var method = instance.GetType().GetMethod("GetSmt");
        object res = method.Invoke(instance, null);
        return sw2.ElapsedMilliseconds;

And here are the test results:

Considering code execution, it seems that Roselyn uses some kind of caching mechanism, also I need to mention that every time at “Pass 1” the old Microsoft compiler has beaten Roselyn by 6-7ms which I presume is spent on caching and other operations.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

United States United States
No Biography provided

You may also be interested in...

Comments and Discussions

GeneralMy vote of 2 Pin
John B Oliver2-Oct-12 13:00
memberJohn B Oliver2-Oct-12 13:00 
GeneralRe: My vote of 2 Pin
Djenad3-Oct-12 4:46
memberDjenad3-Oct-12 4:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.151120.1 | Last Updated 4 Sep 2012
Article Copyright 2012 by Djenad
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid