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

P

px1138

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
 
A

A. Sinan Unur

(e-mail address removed) wrote in @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++.
 
P

px1138

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.
 
E

Eric Schwartz

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
 
X

xhoster

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);
};
 
F

fishfry

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?
 
J

John Bokma

fishfry said:
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
 
F

fishfry

John Bokma said:
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.
 
J

John Bokma

fishfry said:
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.
 
C

Charlton Wilbur

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.

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
 
J

John Bokma

Charlton Wilbur said:
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.

Assembly? Build your own processor with TTL?
It
gives you a good point of reference for performance

performance... I rarely worry about that one. Faster hardware is often
cheaper then hiring a programmer. An exception might be embedded. But,
that's a specialization.
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.

A study is preparing someone without specializing too much. I rather
would teach "high level" programming, preferable showing several
different languages (OO, functional, etc.) and managing big projects
compared to kernel level hacking. What is more realistic?
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.

Assembly is just details. I rather read an introduction to computer
algorithms compared to Knuth's MIX stuff. It distracts way too much
IMNSHO.
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.

Moreover, and more important, it's extremely hard to grasp behind a
computer as well. An optimized badly designed algorithm can run way
slower compared to a well thought out algorithm not optimized to use
every bit.
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.

Probably because you are not one of them ;-). I rather see a student who
has a firm understanding of theoretical CS (e.g. can read "An
introduction..." backwards) and can handle 2 languages compared to one
who does kernel hacking and knows 5+ other 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.

Why is that? Are you tied to a chair? :-D
 
A

Alan J. Flavell

Assembly? Build your own processor with TTL?

We tried microcoding, a decade or two back (on IBM 4331/4361
mainframes, which were microcoded machines "under the covers", even
though they looked like 370/XA architecture on the surface).

A good job we didn't invest too much effort into it, though. The idea
came from my then-boss, but it was good fun for someone like me who
had early experience on the STANTEC ZEBRA - but wildly impractical in
the big scheme of things. By the time we could have incorporated it
into a production application program, we had already phased out that
series of hardware!

cheers
 
X

xhoster

He didn't say he was in grad schhol in computers. I've taken several
grad-level classes while I was an undergrad, including some not in my
major.
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?)


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

I am sure you can do it, but not very effectively. Pseudo languages hide a
multitude of sins, which make them highly unrealistic. That is why they
are pseudo languages--no one has been able to reduce them to practise.

Xho
 
C

Charlton Wilbur

JB> performance... I rarely worry about that one. Faster hardware
JB> is often cheaper then hiring a programmer. An exception might
JB> be embedded. But, that's a specialization.

Faster hardware won't help when your programmer just doesn't
understand that he's doing thousands of memory allocations and
deallocations in a tight loop, or that he's using an O(2**n) algorithm
when he can find an O(n ln n) algorithm for the same thing.

It's a commonplace in Perl culture that programmer time is expensive,
and computer time is cheap. But that doesn't mean that performance is
irrelevant, and it sure as hell doesn't mean that a programmer
shouldn't be aware of the various tradeoff possibilities among
implementation difficulty, resource consumption, and speed.

(Hint: When I respond to a point with an entire sentence, responding
to the first ten words of the sentence as if they were all I wrote is
not generally helpful, especially if the rest of the sentence
undercuts your point.)

JB> A study is preparing someone without specializing too much. I
JB> rather would teach "high level" programming, preferable
JB> showing several different languages (OO, functional, etc.) and
JB> managing big projects compared to kernel level hacking. What
JB> is more realistic?

I would say that in the four years of an undergraduate degree it's
entirely capable to be shown several different languages and reach a
minimal level of competence in all of them. A *well-educated*
computer science student will know something about managing big
projects, something about kernel level hacking, something about object
oriented design and programming, something about functional
programming, something about algorithm analysis, something about
computation theory (regular languages, pushdown automata, Turing
machines), something about artificial intelligence.

You're creating a false dichotomy between "kernel level hacking" and
"high level" programming and project management. A *well-educated*
computer science student will learn a good deal about both of those.

JB> Assembly is just details. I rather read an introduction to
JB> computer algorithms compared to Knuth's MIX stuff. It
JB> distracts way too much IMNSHO.

Except that *someone* needs to deal with those details. It's nice to
imagine everything as black boxes and virtual machines all the way
down, but at some point you hit real hardware.

JB> Probably because you are not one of them ;-). I rather see a
JB> student who has a firm understanding of theoretical CS
JB> (e.g. can read "An introduction..." backwards) and can handle
JB> 2 languages compared to one who does kernel hacking and knows
JB> 5+ other languages...

Again, false dichotomy. A *well-educated* student should have a firm
understanding of theoretical *and* practical CS. This means
understanding the math *and* knowing one's way around a debugger.

Charlton
 
J

John Bokma

I am sure you can do it, but not very effectively. Pseudo languages
hide a multitude of sins, which make them highly unrealistic. That is
why they are pseudo languages--no one has been able to reduce them to
practise.

Nonsense of course, a good example is MIX, and pseudo pascal (IIRC) as used
in An introduction to algorithms.
 
J

John Bokma

Charlton Wilbur said:
understanding of theoretical *and* practical CS. This means
understanding the math *and* knowing one's way around a debugger.

Funny you mention it, I had to use this year the Perl debugger. Couldn't
remember when it was the last time :-D.
 
A

Anno Siegel

John Bokma said:
Nonsense of course, a good example is MIX, and pseudo pascal (IIRC) as used
in An introduction to algorithms.

MIX isn't a pseudo language, it's a real assembler with real
implementations. That it wasn't written for any specific hardware
makes no difference. Nothing is glossed over in a MIX program, all
the details are there.

Anno
 
A

axel

fishfry said:
(e-mail address 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?

Quite easily. I did an M.Sc. in computer science despite
having done my first degree as an MA in Mediaeval History.
(I had done some computing before, but it was not a
requirement for entry to the course).

Axel
 
A

axel

Charlton Wilbur said:
It's a commonplace in Perl culture that programmer time is expensive,
and computer time is cheap. But that doesn't mean that performance is

It is true. I remember a project I had to write in C++ which I
could probably have done in a fifth of the time in Perl (which
was not an option). Still, who was I to complain too much
as I got paid for it.
irrelevant, and it sure as hell doesn't mean that a programmer
shouldn't be aware of the various tradeoff possibilities among
implementation difficulty, resource consumption, and speed.
(Hint: When I respond to a point with an entire sentence, responding
to the first ten words of the sentence as if they were all I wrote is
not generally helpful, especially if the rest of the sentence
undercuts your point.)
I would say that in the four years of an undergraduate degree it's
entirely capable to be shown several different languages and reach a
minimal level of competence in all of them. A *well-educated*

True. But how many different languages? Certainly C, either Java
or C++, assembly, and a functional language. I would not include
Perl in the list as it makes things too easy (if I may use that
phrase) and therefore not good for teaching.
computer science student will know something about managing big
projects, something about kernel level hacking, something about object
oriented design and programming, something about functional
programming, something about algorithm analysis, something about
computation theory (regular languages, pushdown automata, Turing
machines), something about artificial intelligence.
You're creating a false dichotomy between "kernel level hacking" and
"high level" programming and project management. A *well-educated*
computer science student will learn a good deal about both of those.

Are you sure? My experience is that computer science courses actually
teach very little about what is demanded in the commercial world.
Subjects such as system administration, routing, file storage
solutions, and so on.

I worked in the Internet department of a cable ISP. I think I was
the only person there who had a computing degree. A couple had
engineering degrees, one a music degree (if that is the correct
word for a qualification from a conservatory), and the others no
degree. One of those without a degree told me he had given it up
as he could make more money as a sys admin and travel the world
doing it; another was an expert on Cisco routers.

Axel
 
C

Charlton Wilbur

ax> It is true. I remember a project I had to write in C++ which I
ax> could probably have done in a fifth of the time in Perl (which
ax> was not an option). Still, who was I to complain too much as I
ax> got paid for it.

Again: when I respond to a point with an entire sentence, responding
to the first phrase of the sentence as if it was the whole point is
NOT HELPFUL, especially when the rest of the sentence undercuts your
point.

ax> True. But how many different languages? Certainly C, either
ax> Java or C++, assembly, and a functional language. I would not
ax> include Perl in the list as it makes things too easy (if I may
ax> use that phrase) and therefore not good for teaching.

At a minimum, I'd say C (for being close to the machine), FORTRAN or
COBOL (for business reasons), LISP or Scheme (no code/data dichotomy),
Haskell or ML (modern functional programming), Smalltalk or Eiffel
(for pure, powerful object-orientation), assembly of some sort (for
being even closer to the machine than C), and Java, C#, or C++
(because that's what industry uses).

ax> Are you sure? My experience is that computer science courses
ax> actually teach very little about what is demanded in the
ax> commercial world. Subjects such as system administration,
ax> routing, file storage solutions, and so on.

That's because what the commercial world needs are not computer
scientists but system administrators, network administrators, file
server administrators, and so on. It makes about as much sense to
expect a computer scientist to be good at server or network
administration as it does for a mathematician to be good at
accounting. In the absence of respected accounting degrees, no doubt
many qualified accountants would have no choice but to get math
degrees, and that's the situation we're in with computer science:
worthwhile vocational degrees in system administration are few and far
between, but businesses usually require a college degree, so any
degree will do.

Charlton
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top