Re: A program to measure flops in Perl (should it be this "off"?)
- From: xhoster@xxxxxxxxx
- Date: 30 Aug 2005 23:29:48 GMT
px1138@xxxxxxxxx wrote:
> I am in a grad level computer architecture class.
Then you should know better than to ask questions without providing
any relevant information.
> My personal caveat is that I suck at C/C++, I wouldn't even know where
> to start. However, I have coded in Perl at many internships and other
> projects so I wanted to use Perl. Well, I am getting downright horrible
> performance from my Perl script (I would say a factor of 100 or more
> slower than my CPU should be).
I get a factor of 33 difference for my simple program. 100-fold slower
than an equivalent C code? Sure, I could believe that. Of course, that
has nothing to do with how fast your CPU "should be", as you are asking
your CPU to do entirely different things.
> I have pretty much the same sort of
> algorithm as a friend of mine has in C++ and he is getting something
> like ~500Mflops on is laptop while my perl script (running perl for
> windows, I know, I know) says 2-5Mflop! Now I know Perl is interpretted
> but should it be THAT slow? If so, why?
Because it does a lot of things C doesn't, like extra dereferencing,
checking for definedness, automatic conversion from string representations
to integer and floating point representations, automatic bounds checking
and reallocation of arrays and strings, and on and on and on. All the
stuff that makes Perl Perl rather than C. Afterall, if Perl only does
what C does, we would just use C.
> If not, so I am just coding
> something oddly?
How should we know? You haven't shown us any of your coding.
Xho
[~/perl_misc]$ time ./a.out
125000000067108896.000000
4.470u 0.010s 0:05.44 82.3% 0+0k 0+0io 93pf+0w
[~/perl_misc]$ time perl overhead2.pl
125000000067108896.000000
148.810u 0.400s 3:06.70 79.9% 0+0k 0+0io 365pf+0w
[~/perl_misc]$ cat overhead2.pl
use strict;
my $y;
foreach (1..500_000_000) {
$y+=$_;
};
printf "%f\n", $y;
[~/perl_misc]$ cat overhead2.c
int main() {
double y=0;
int x;
for (x=1; x<=500000000; x++) {
y+=x;
};
printf("%f\n",y);
};
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
.
- References:
- Prev by Date: Re: problem about the perl code. thanks for any comments
- Next by Date: Re: problem about the perl code. thanks for any comments
- Previous by thread: Re: A program to measure flops in Perl (should it be this "off"?)
- Next by thread: Re: A program to measure flops in Perl (should it be this "off"?)
- Index(es):
Relevant Pages
|