Re: A program to measure flops in Perl (should it be this "off"?)



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
.



Relevant Pages

  • Re: Why does Perl use more resource than Php?
    ... A Perl app that means a large number ... >> require less CPU for a similar app, so the language may well be ... Gunnar Hjalmarsson ...
    (comp.lang.perl.misc)
  • Re: is it possible to efficiently read a large file?
    ... a general purpose language like perl. ... buffer size. ... I find that number impossible to believe unless you're doing somethere very fancy OR you have more than 4GB RAM and are reading it out of cache ... I don't think CPU reporting in these cases is very meaningful. ...
    (comp.lang.perl.misc)
  • RE: switching perl version
    ... Another poster said Perl is the last place you should look, ... You should also be looking on metalink for answers on how to trace ... Subject: switching perl version ... oracle 8i was using 30% cpu approx. ...
    (perl.dbi.users)
  • tar gone wild under perl
    ... I am having a problem with tar suddenly taking 100% of the cpu and never ... This is perl, ... Is this a bug in FreeBSD, Apache, or Perl? ...
    (comp.unix.bsd.freebsd.misc)
  • Re: how to capture certain fields of the output???
    ... Report of any computer, where i can capture the CPU information, ... If cat can read, perl can too. ... I assume that was supposed to be $CPU. ... there are no CPAN module flaws, feel free to post QA tests right here ...
    (comp.lang.perl.misc)