Re: [Vala] Why Vala is slower than Mono?
- From: Simon Werbeck <simon werbeck googlemail com>
- To: pinggi centrum cz
- Cc: vala-list gnome org
- Subject: Re: [Vala] Why Vala is slower than Mono?
- Date: Sat, 02 Jun 2012 16:39:46 +0200
Am Samstag, den 02.06.2012, 15:47 +0200 schrieb pinggi centrum cz:
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?
_______________________________________________
vala-list mailing list
vala-list gnome org
https://mail.gnome.org/mailman/listinfo/vala-list
Note that in Vala you can define functions outside of classes. I guess
Mono will optimize away the class definition, since it is not referenced
anywhere. But in Vala you have the added cost of the glib type system.
In your example you can get rid of the class and rewrite to:
public void 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\n", t1.elapsed(),
t2.elapsed());
}
Now with optimization turned on I get roughly the same times. That said,
I am not a Vala developer, so maybe someone else has a better
explanation.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]