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 <qb...@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.hu...@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