Folks,

I recently read that gcc is a dog. (I am heavily paraphrasing for the sake of brevity). The same program compiled with a different compiler ran significantly faster.

That specific article itself is irrelevant. But what inquiring (and clueless) minds want to know, is my OS X perl slower that my ActiveState perl because of the compilers used to compile the perl binary in the first place. Yes, I know comparing different platforms is tricky -- cpu speed, ram, cpu architecture, other daemons running, etc. But, in an overall sense of things -- does gcc make things slower?

In some spare time I did some empirical testing using the same script on perl 5.6.1 on Win2k (PIII/833 Mhz/512 Mb ram/apache, and no other significant daemons) versus perl 5.6.1 on OS X (G3/600 Mhz/640 Mb ram/apache, and no other significant daemons). I started with a file with email addresses (one per line), many being duplicates. A small perl script first removed the duplicates then sorted results, and wrote 'em out to another file. The only catch -- the original file was 145 Mb with close to 3.5 million lines (I created that by simply cat-in >> the same file over and over again to an output file until my fingers got tired). The end result was a svelte, 600+ line file, about 11 kb.

The operation took about 122 secs on the Windows machine, and 299 seconds on the iBook.

Yes, the iBook CPU is 200 Mhz slower, and god only knows how we can compare a P3 to G3, but 2.5 times the time taken is a bit much. Coming back to my initial assertion -- Could some of this be attributed to the way the perl binary is compiled?


The test script follows. The only difference on the platforms was the shebang line.

I used the following script (some code is mine, some from the cookbook). I used my own crude benchmark.

#!c:\perl\bin\perl.exe -w
my $start = time();

my $file = "c:/htdocs/testers/dupes/dupes2.txt";

open IF, $file or die $!;
open OF, ">c:/htdocs/testers/dupes/filewithoutdupes.txt" or die $!;

my @list;
push(@list, $_) while (<IF>);

my %seen = ();
my @uniq;
foreach my $item (@list) {
push(@uniq, $item) unless $seen{$item}++;
}

my @uniqsorted = sort @uniq;
print OF @uniqsorted;

close IF;
close OF;
my $end = time();
my $dur = $end - $start;
print "This took $dur seconds\n";

Reply via email to