[Vala] Why Vala is slower than Mono?



I read that Vala is fast because it is translated to C and then compiled to the machine code. I have been 
encouraged to find out how much Vala is faster than Mono. So I made a speed test.

The test program creates an array 100 000 000 integers long and then it fills the array with numbers 
incrementing by one. Both time durations are printed.

Firstly, C# source:

using System;
using System.Diagnostics;

namespace MonoTest
{
    class MainClass
    {
        public static void Main (string[] args)
        {
            Stopwatch t1 = new Stopwatch ();
            Stopwatch t2 = new Stopwatch ();
                        t1.Start ();                     int[] matrix = new int[100000000];
            int i;

            t1.Stop ();

            t2.Start ();
                for (i = 0; i < matrix.Length; i++) {
                matrix [i] = i;
            }

            t2.Stop ();
                Console.WriteLine ("Took: creating: {0}, processing: {1}", t1.ElapsedMilliseconds / 1000.0, t2.ElapsedMilliseconds / 1000.0);
        }
    }
}

Compiled by: dmcs Main.cs
Run by: ./Main.exe
Output: Took: creating: 0.388, processing: 0.212

Now, Vala source:

using GLib;

public class HelloVala: GLib.Object {
        public static int main (string[] args) {

        Timer t1 = new Timer();
        Timer t2 = new Timer();
                    t1.start();                 int[] matrix = new int[100000000];
        int i;

        t1.stop();

        t2.start();
            for (i = 0; i < matrix.length; i++)
        {
            matrix[i] = i;
        }

        t2.stop();
            stdout.printf("Took: creating: %f, processing: %f", t1.elapsed(), t2.elapsed());                 return 0;
    }
}

Compiled by: valac main.vala
Run by: ./main
Output: Took: creating: 0.000034, processing: 2.101480

Compiled by: valac main.vala -X -O0
Run by: ./main
Output: Took: creating: 0.000032, processing: 2.058595

Compiled by: valac main.vala -X -O1
Run by: ./main
Output: Took: creating: 0.000015, processing: 0.434786

Compiled by: valac main.vala -X -O2
Run by: ./main
Output: Took: creating: 0.000034, processing: 0.455629

Compiled by: valac main.vala -X -O3
Run by: ./main
Output: Took: creating: 0.000033, processing: 0.364947
 
Compiled by: valac main.vala -X -Ofast
Run by: ./main
Output: Took: creating: 0.000019, processing: 0.352727

Compiled by: valac main.vala -X -Os
Run by: ./main
Output: Took: creating: 0.000033, processing: 0.415005


It seems that Vala is 10 times slower than mono by default and 2 times with optimizations.
How is that possible?




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]