Re: [Vala] Why Vala is slower than Mono?

2012-06-04 Thread Alberto Mardegan
Hi,

On 06/02/2012 04:47 PM, pin...@centrum.cz wrote:
> 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.

thanks for taking the time to write a benchmark! I would however suggest
you to try measuring the performance of different operations: string
methods (concatenation and printf-like composition are very often used
in real-life applications), lists/arrays, objects creation, argument
passing, etc.

As Jürg wrote, I also suspect that the bad performance you are seeing in
your benchmark is due to the memory allocation; I would think that the
performance of arithmetic operations is more or less equivalent in all
compiled languages, so it's not something I would care to measure.

Ciao,
  Alberto
___
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] Why Vala is slower than Mono?

2012-06-02 Thread Simon Werbeck
Am Samstag, den 02.06.2012, 15:47 +0200 schrieb pin...@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[1];
>  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[1];
>  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.34, processing: 2.101480
>  
>  Compiled by: valac main.vala -X -O0
>  Run by: ./main
>  Output: Took: creating: 0.32, processing: 2.058595
>  
>  Compiled by: valac main.vala -X -O1
>  Run by: ./main
>  Output: Took: creating: 0.15, processing: 0.434786
>  
>  Compiled by: valac main.vala -X -O2
>  Run by: ./main
>  Output: Took: creating: 0.34, processing: 0.455629
>  
>  Compiled by: valac main.vala -X -O3
>  Run by: ./main
>  Output: Took: creating: 0.33, processing: 0.364947
>   
>  Compiled by: valac main.vala -X -Ofast
>  Run by: ./main
>  Output: Took: creating: 0.19, processing: 0.352727
>  
>  Compiled by: valac main.vala -X -Os
>  Run by: ./main
>  Output: Took: creating: 0.33, 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[1];
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.

___
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] Why Vala is slower than Mono?

2012-06-02 Thread Jürg Billeter
On Sat, 2012-06-02 at 15:47 +0200, pin...@centrum.cz wrote:
>  Compiled by: dmcs Main.cs
>  Run by: ./Main.exe
>  Output: Took: creating: 0.388, processing: 0.212
>  
>  [...]
>  
>  Compiled by: valac main.vala -X -O2
>  Run by: ./main
>  Output: Took: creating: 0.34, processing: 0.455629

> [...]

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

For large heap allocations, as in your example, glibc (and thus Vala)
uses mmap which uses copy-on-write of a zero page to only physically
allocate if and when the memory area is actually written to. Mono
doesn't appear to use the same approach. This is why the allocation is
faster and the processing is slower with Vala. You need to compare the
sum of allocation and processing for a fair comparison, and in that case
Vala wins with typical -O2 optimizations according to your numbers.

Alternatively, you could configure glibc to never use mmap and rerun the
tests. I don't remember the specific environment variables off the top
of my head but you should be able to find them in the man pages.

Regards,
Jürg

___
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list