Click here to get back home

Performance on Windows: Cygwin is much faster. Why?

 HomeNewsGroups | Search | About
 comp.lang.perl.misc    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Performance on Windows: Cygwin is much faster. Why? Dutch 06-07-2008
Posted by Dutch on June 7, 2008, 8:26 am
Please log in for more thread options
Below is a small program to calculate some values using Lehmer's algorithm.
Running it on Windows XP, I found some rather strange performance facts.

Using ActiveState 5.10, it runs in 1117 seconds.

With Strawberry 5.10, it takes 945 seconds.

But with Cygwin (using version Perl 5.8), on the same machine, it finishes
in 488 seconds, it is twice as fast!

These results are reproducible.

Why would Cygwin be faster by such a large margin? Is it because of the
underlying libraries being more efficient or am I overlooking something?

Following, the program:

# Given: G(n) = ( 7**5 * G(n-1) ) % ( 2^^31 - 1 )
# Find : X = G( 943683858) = 133481
# Y = G(1657543960) = 447352

$| = 1;

my $starttime = time();

my $n = 0;
my $g = 555;

my $multiplier = 7**5;
my $mask = 2**31 - 1;

for (; $n < 943_683_858; $n++) { $g = ($multiplier * $g) % $mask; }

my $seconds = time() - $starttime;
print "Found X=$g in $seconds seconds, ";

for (; $n < 1_657_543_960; $n++) { $g = ($multiplier * $g) % $mask; }

$seconds = time() - $starttime;
print "Y=$g in $seconds seconds.\n";

# END OF PROGRAM



Posted by Ben Morrow on June 7, 2008, 4:45 pm
Please log in for more thread options

> Below is a small program to calculate some values using Lehmer's algorithm.
> Running it on Windows XP, I found some rather strange performance facts.
>
> Using ActiveState 5.10, it runs in 1117 seconds.
>
> With Strawberry 5.10, it takes 945 seconds.
>
> But with Cygwin (using version Perl 5.8), on the same machine, it finishes
> in 488 seconds, it is twice as fast!

Can you test this with Cygwin 5.10 and Strawberry 5.8? I suspect the
difference is more likely to be a 5.10 slowdown than a Cygwin speedup;
if this is the case, it should probably be reported to p5p.

Also, can you post the results of

perl -MDevel::Peek -e"Dump 1_657_543_960 * 7**5"

with each perl? If some of your perls have 32bit and some 64bit
integers, that is likely to make a difference to performance.

Ben

--
Razors pain you / Rivers are damp
Acids stain you / And drugs cause cramp. [Dorothy Parker]
Guns aren't lawful / Nooses give
Gas smells awful / You might as well live. ben@morrow.me.uk

Posted by Dutch on June 7, 2008, 5:20 pm
Please log in for more thread options

> Can you test this with Cygwin 5.10 and Strawberry 5.8?

Sure, I'll try that tomorrow.

> Also, can you post the results of
> perl -MDevel::Peek -e"Dump 1_657_543_960 * 7**5"

Can't do it for ActiveState right now, but:

==========
Strawberry
==========

perl -v says this:
This is perl, v5.10.0 built for MSWin32-x86-multi-thread

The output you requested:

SV = NV(0x9d59fc) at 0x9b98b4
REFCNT = 1
FLAGS = (PADTMP,NOK,READONLY,pNOK)
NV = 27858341335720

======
Cygwin
======

perl -v says this:
This is perl, v5.8.8 built for cygwin-thread-multi-64int

The output you requested:

SV = IV(0x10029318) at 0x10010fc0
REFCNT = 1
FLAGS = (PADBUSY,PADTMP,IOK,READONLY,pIOK)
IV = 27858341335720


I'm not sure what the output means, but I see that the version under Cygwin
talks about 64int. Perhaps this (as you mentioned) point to using 64-bit
integers? I can see why that would speed things up. However, I'm guessing
here.

This all runs on an Intel Core Duo processor, btw, not sure if it's
relevant.

Dutch



Posted by Ben Morrow on June 7, 2008, 7:00 pm
Please log in for more thread options

>
> perl -v says this:
> This is perl, v5.10.0 built for MSWin32-x86-multi-thread
>
> The output you requested:
>
> SV = NV(0x9d59fc) at 0x9b98b4
> REFCNT = 1
> FLAGS = (PADTMP,NOK,READONLY,pNOK)
> NV = 27858341335720

This means some of your intermediate results are being stored as NVs,
that is, as C doubles, because they are too big to fit in an IV, which
in this case is a 32bit C long.

> perl -v says this:
> This is perl, v5.8.8 built for cygwin-thread-multi-64int
>
> The output you requested:
>
> SV = IV(0x10029318) at 0x10010fc0
> REFCNT = 1
> FLAGS = (PADBUSY,PADTMP,IOK,READONLY,pIOK)
> IV = 27858341335720

This means that all intermediate results are IVs, which in this case
are 64bit C long longs. Integer arithmetic is much faster than floating-
point arithmetic (and, probably, arithmetic that has to keep
converting from one to the other is slower than either), so that's why
cygwin is faster.

AFAICT, it is not possible to build a perl for Win32 with the
equivalent of use64bitint, the way the cygwin perl is built, so if you
need speed, either get a 64bit processor and OS and build a 64bit perl
or stick to cygwin.

Ben

--
#!/bin/sh
quine="echo 'eval $quine' >> \$0; echo quined"
eval $quine
# [ben@morrow.me.uk]

Posted by Dutch on June 8, 2008, 4:49 am
Please log in for more thread options

>
> This means that all intermediate results are IVs, which in this case
> are 64bit C long longs. Integer arithmetic is much faster than floating-
> point arithmetic [...], so that's why cygwin is faster.

I can understand how this works, thanks for the explanation.

> AFAICT, it is not possible to build a perl for Win32 with the
> equivalent of use64bitint, the way the cygwin perl is built, so if you
> need speed, either get a 64bit processor and OS and build a 64bit perl
> or stick to cygwin.

The performance isn't a problem, I just thought it was rather strange that
one was twice as fast on the same hardware. I will be migrating away from
Windows anyway (unrelated to this issue).

Thanks for teaching me something about the inner workings of Perl! ;-)

I'm guessing the benchmarks with the different versions of Perl on Windows
aren't necessary anymore as the mystery is solved. However, if anyone really
wants to see the results, I'll do it and will post here. Just let me know.

Dutch



Similar ThreadsPosted
installing dbd::mysql via cygwin on windows December 4, 2004, 1:31 am
C/C++:Can't Use "ssh/rsh ... ps ..." To Windows: cygwin not allowed, application conflicts May 9, 2005, 12:24 pm
several problems with cygwin perl, Activeperl, perlmagick and Apache (Windows) December 21, 2005, 3:08 am
What is "$^O" on Cygwin? September 18, 2005, 12:26 am
Why $1 not work in cygwin? July 10, 2005, 11:57 pm
Bit-Vector-6.4 on Cygwin December 19, 2005, 4:25 am
Known issues with Perl under Cygwin? August 26, 2005, 6:43 pm
Why perl -n0e doesn't work on cygwin and NT December 6, 2007, 3:57 am
Confusion of Win32::ODBC under CygWin. Please help... August 22, 2004, 5:03 am
Re: Cygwin error regarding profile.global September 4, 2006, 6:16 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap