Re: [Vala] Fwd: Why is Vala 10 times slower than C ?



Or do a Vala program without GLib (using the posix profile for instance) and
it will probably be closer to the C version.
But again, you are comparing two very different things. Vala provides an
object-oriented language on top of the GObject system, which in the end
compiles to C code. Of course if you don't need to use objects and you don't
want the Vala syntax, just use plain C and you won't have any overhead.
Otherwise you need to live with some kind of overhead and I can tell you,
Vala's overhead for what it provides is minimal.

*Alexandre Rosenfeld*

On Mon, Jun 6, 2011 at 09:21, Гаврилов Максим <ulltor gmail com> wrote:

Why do you call it an equivalent version if there's no sign of Glib,
garbage
collection, etc. in this code?

Just write a Glib-based wc in C, and it will be as fast as in Vala.
06.06.2011 17:07 пользователь "Serge Hulne" <serge hulne gmail com>
написал:
Nope !

Here is the equivalent version in C:

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

int main(int argc, char** argv)

{

FILE *fp = NULL;

char buff[100], *fileName = NULL;

int wcnt = 0;

int lcnt = 0;

if (argc <2)

{

fprintf(stderr, "Usage: wc <file_name>\n");

exit(1);

}

fileName = argv[1];

if ( (fp = fopen(fileName, "r")) == NULL)

{

perror(fileName);

exit(1);

}

while (!feof(fp))

{

buff[0] = '\0';

fgets(buff, sizeof buff/sizeof(char), fp);

lcnt++;

char * str = malloc(sizeof(char)*101);

strcpy(str, buff);

char * pch;

pch = strtok (buff," ");

while (pch != NULL)

{

//printf ("%s\n",pch);

pch = strtok (NULL, " ");

wcnt++;

}

}

fclose(fp);

printf("word count: %i words, lines = %d\n", wcnt, lcnt);

return 0;

}



Serge.



---------- Forwarded message ----------
From: Qball Cow <qball aggervaccae nl>
Date: Mon, Jun 6, 2011 at 2:15 PM
Subject: Re: [Vala] Why is Vala 10 times slower than C ?
To: Serge Hulne <serge hulne gmail com>
Cc: vala-list gnome org


This is not really a fair comparison. Try writing the same code as you
wrote
in vala in C and then compare.

You are now comparing a probably very highly optimized 'wc' with a naïve
implementation in vala.



On Mon Jun 6 14:12:37 2011, Serge Hulne wrote:

I used "wordcount" as a test to compare the processing speed of Vala
against
C:


I obtained the following result:

---
C:
---
serge:vala serge2$ time wc ../shakespeare.txt
495200 2703240 15862370 ../shakespeare.txt

real 0m0.194s
user 0m0.176s
sys 0m0.015s

---
Vala:
---
serge:vala serge2$ time ./hello
lc = 495201. wc = 3170980

real 0m2.258s
user 0m2.223s
sys 0m0.028s


-------

The vala code is as follows:

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

var f = FileStream.open("../shakespeare.txt", "r");
var line = "";
var wc = 0;
var lc = 0;

while (!f.eof()) {
line = f.read_line(); lc++;
if (line == null) break;
//stdout.printf("line = %s\n", line);
var words = line.split(" ");
for (int i=0; i<words.length; i++) {
//stdout.printf("word = %s\n", words[i]);
wc++;
}
}

stdout.printf("lc = %d. wc = %d\n", lc, wc);
return 0;
}
}




_______________________________________________
vala-list mailing list
vala-list gnome org
http://mail.gnome.org/mailman/listinfo/vala-list


_______________________________________________
vala-list mailing list
vala-list gnome org
http://mail.gnome.org/mailman/listinfo/vala-list




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