Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > A program to measure flops in Perl (should it be this "off"?)

Reply
Thread Tools

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

 
 
px1138@gmail.com
Guest
Posts: n/a
 
      08-30-2005
I am in a grad level computer architecture class. Although it does not
have any programming prereqs most of the students are CS (I am EE), so
the first assignment was to write a little program to determine the
amount of flops per second your computer runs at. It is suppose to be a
short program, and apart from making sure you use a good timer and run
for long enough to ensure accuracy it doesn't have to include any
really big optimizations (i.e. making sure all the data fits in cache
to minimize memory transfer, doing something like LINPACK and making
sure your # ops >> # data, etc etc).

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 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? If not, so I am just coding
something oddly?

-Josh

 
Reply With Quote
 
 
 
 
A. Sinan Unur
Guest
Posts: n/a
 
      08-30-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote in news:1125433075.641083.64400
@g49g2000cwa.googlegroups.com:


> but should it be THAT slow? If so, why? If not, so I am just coding
> something oddly?


Please read the posting guidelines for this group.

Show what you are doing (i.e. post a self-contained script that exhibits
the problem), and we might be able to comment.

OTOH, Perl does provide some extra goodies, and there is a cost associated
with that.

Sinan

PS: There is no language called C/C++. It is either C or C++.

--
A. Sinan Unur <(E-Mail Removed)>
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/cl...uidelines.html
 
Reply With Quote
 
 
 
 
px1138@gmail.com
Guest
Posts: n/a
 
      08-30-2005
Meh, then I'll just deal with it . Was just wondering if in general i
should be seeing such dismal performance as compared to C. No need for
others to respond, sorry for crashing your group, I'll be going now.

 
Reply With Quote
 
Eric Schwartz
Guest
Posts: n/a
 
      08-30-2005
(E-Mail Removed) writes:
> Meh, then I'll just deal with it . Was just wondering if in general i
> should be seeing such dismal performance as compared to C.


The problem is, there is no "in general". While Perl programs often
have a huge startup cost relative to C or C++ programs, sometimes the
code perl generates for a given construct is faster than a
poorly-written C version of the same construct (well-written C is
almost always going to be faster). Sometimes it will be worse. The
only way to know is for you to show us your code.

> No need for others to respond, sorry for crashing your group, I'll
> be going now.


That's your choice. Hope it works out for you.

-=Eric
 
Reply With Quote
 
xhoster@gmail.com
Guest
Posts: n/a
 
      08-30-2005
(E-Mail Removed) 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
 
Reply With Quote
 
fishfry
Guest
Posts: n/a
 
      08-31-2005
In article <(E-Mail Removed). com>,
(E-Mail Removed) wrote:

> I am in a grad level computer architecture class. Although it does not
> have any programming prereqs most of the students are CS (I am EE), so
> the first assignment was to write a little program to determine the
> amount of flops per second your computer runs at. It is suppose to be a
> short program, and apart from making sure you use a good timer and run
> for long enough to ensure accuracy it doesn't have to include any
> really big optimizations (i.e. making sure all the data fits in cache
> to minimize memory transfer, doing something like LINPACK and making
> sure your # ops >> # data, etc etc).
>
> My personal caveat is that I suck at C/C++, I wouldn't even know where
> to start.


Pardon me for asking ... I'm a bit of an old timer. How do you get to
grad school in computers without knowing a compiled language?
 
Reply With Quote
 
John Bokma
Guest
Posts: n/a
 
      08-31-2005
fishfry <(E-Mail Removed)> wrote:

> Pardon me for asking ... I'm a bit of an old timer. How do you get to
> grad school in computers without knowing a compiled language?


Some questions:

- what is a compiled language

- is Java a compiled language
- is Perl a compiled language
- is C# a compiled language
- is Prolog a compiled language
- is Haskell a compiled language

--
John Small Perl scripts: http://johnbokma.com/perl/
Perl programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html

 
Reply With Quote
 
fishfry
Guest
Posts: n/a
 
      09-01-2005
In article <Xns96C2EE1F15694castleamber@130.133.1.4>,
John Bokma <(E-Mail Removed)> wrote:

> fishfry <(E-Mail Removed)> wrote:
>
> > Pardon me for asking ... I'm a bit of an old timer. How do you get to
> > grad school in computers without knowing a compiled language?

>
> Some questions:
>
> - what is a compiled language
>
> - is Java a compiled language
> - is Perl a compiled language
> - is C# a compiled language
> - is Prolog a compiled language
> - is Haskell a compiled language


Fair enough.

How do you get to grad school in computers without knowing C or C++?

Like I say, I haven't been to school in a while. I'm curious.
 
Reply With Quote
 
John Bokma
Guest
Posts: n/a
 
      09-01-2005
fishfry <(E-Mail Removed)> wrote:

> How do you get to grad school in computers without knowing C or C++?


What are the advantages of C/C++ over:

- Java
- C#

(to keep it simple)

Oh, what happened to assembly language and hex code entry (and building
your own hardware for that matter?)

> Like I say, I haven't been to school in a while. I'm curious.


You can even study CS with a pseudo language and without using computers.

--
John Small Perl scripts: http://johnbokma.com/perl/
Perl programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html

 
Reply With Quote
 
Charlton Wilbur
Guest
Posts: n/a
 
      09-01-2005
>>>>> "JB" == John Bokma <(E-Mail Removed)> writes:

JB> fishfry <(E-Mail Removed)> wrote:
>> How do you get to grad school in computers without knowing C or
>> C++?


JB> What are the advantages of C/C++ over:

JB> - Java - C#

JB> (to keep it simple)

Pedagogically? C teaches you how to deal with manual memory
management, and is about as bare-bones as it's possible to get. It
gives you a good point of reference for performance and programming
complexity, even for toy programs: once you've dealt with the Sieve of
Eratosthenes in C, for instance, you can compare the difficulty of
implementation, resource consumption, and speed against LISP, Perl,
Haskell....

From a practical point of view, C and C++ are the common
implementation languages of operating systems and other languages. It
is at a sweet spot for some tasks, and trying to use a language like
Java or Perl or C# for those tasks is a mistake. Anyone doing any
work in operating systems is going to need to cope with the Linux
kernel on some level.

This is not to say that Java and C# do not *also* have pedagogical uses.

JB> Oh, what happened to assembly language and hex code entry (and
JB> building your own hardware for that matter?)

Computer scientists should be dealing with assembly language too;
knowing a little bit about hardware is nice.

>> Like I say, I haven't been to school in a while. I'm curious.


JB> You can even study CS with a pseudo language and without using
JB> computers.

You *can*, but a great deal of applied computer science is about
tradeoffs, and that's hard to grasp entirely on paper.

As for myself, I'm deeply suspicious of computer science graduates,
let alone graduate students, who don't have at least a glancing
knowledge of a half-dozen computer languages. I'm not that old, and
if I had been taught only "industry relevant" languages, I'd never
have been able to pick up Java, Perl, PHP, or Objective-C.

Charlton


--
cwilbur at chromatico dot net
cwilbur at mac dot com
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
t flip flops danaitsa_thebest@hotmail.com VHDL 18 05-24-2006 05:05 PM
t flip flops danaitsa_thebest@hotmail.com VHDL 0 05-17-2006 03:23 PM
Latches and flip flops crazyrdx VHDL 6 04-09-2006 11:09 PM
ATM IMA Link Flops like clockwork BitBucket Cisco 1 03-05-2004 03:49 PM
Need statndadt code for calculate MIPS and FLOPS Andreas Weichert C++ 1 11-25-2003 09:52 AM



Advertisments