From: Brian Hurt <bhurt@spnz.org>
To: Michael Walter <michael.walter@gmail.com>
Cc: skaller <skaller@users.sourceforge.net>, Jon <jdh30@cam.ac.uk>,
<caml-list@yquem.inria.fr>
Subject: Re: [Caml-list] The boon of static type checking
Date: Sat, 12 Feb 2005 09:22:10 -0600 (CST) [thread overview]
Message-ID: <Pine.LNX.4.44.0502120837090.5563-100000@localhost.localdomain> (raw)
In-Reply-To: <877e9a17050206221653d14456@mail.gmail.com>
On Mon, 7 Feb 2005, Michael Walter wrote:
> On Sun, 6 Feb 2005 23:34:02 -0600 (CST), Brian Hurt <bhurt@spnz.org> wrote:
> > Probably a bad idea, but I've got to jump in here.
> >
> > Full disclosure: I *hate* C++. Mainly because I've actually written real
> > programs in it. The next time I have to use C++ in any sort of serious
> > way I'm registering c++sucks.com and starting a website to catalog all the
> > different ways C++ sucks. Feel free to stop reading at this point.
> :-)
>
> > ...
> > > g++ seems to generate better
> > > code than ocamlopt for similar simple problems
> > > (see Alioth for quantitative evidence given silly
> > > set of sample 'problems')
> >
> > Yep. And, conservatively, 10 times as much effort has gone into the gcc
> > optimizer as the Ocaml optimizer. Possibly 100 times. For, according to
> > Alioth, about a 10% improvement. It's only with gcc 3.x that C++ managed
> > to beat Ocaml on performance.
> More effort having gone into gcc and better performance of gcc are
> arguments pro gcc, right? ;-)
If the 10-30% performance advantage (best case) is the difference between
success and failure, then maybe. Of course, going to a professional C/C++
complier like Intel's cc, or IBM's xlc, will buy you another 5-10% over
GCC, as they've put maybe 10x more effort into their compilers than has
gone into gcc.
This is, of course, assuming that a) you are falling into the best case
situation, and b) you'd have implemented the same algorithm in both cases,
and c) time to implement is irrelevent. Of course, if time to implement
really is irrelevent, than going to hand tuned assembly will buy you
another 10-30%, generally, and occassionally 2x performance (SSE/Altivec
optimizations).
>
> > > IMHO the single major inefficiency in C++ is also a source
> > > of efficiency -- lack of a garbage collector.
> >
> > It's a source of efficiency on the small scale- it's easy to write a 1,000
> > line program with hand allocation. Rather harder to write a 10,000 line
> > program, and a major bitch to write a 100,000 line program without garbage
> > collection.
> Personally I like it that in C++ you actually have the choice to use
> appropriate garbage collection schemes when you desire to do (yep,
> multiple kind of GCs for different subsystems/data/... is a win).
> Makes it easier with > 1,000,000 line programs :-)
Yes! Having a choice means you can fuck it up!
And I disbeleive the "makes it easier with large programs" statement.
It's contrary to all evidence I've seen, and all my experience. The
complexity of a program is, I've postulated, a function of the number of
interactions between different parts of the code. And that therefor the
innate complexity approximately scales with the square of the number of
lines of code- so a 10,000 line program is 100 times as complicated as a
1,000 line program. Brooks has evidence of this as well.
So the trick to managing complexity is limiting the interactions (to just
the interactions needed). Unexpected/unintended interactions are
generally called "bugs". As a side note, this is one of the really nice
things about applicative semantics.
Now, if there are multiple different "memory management domains", that
require different behaviors, you are now introducing new interactions to
the program. This is introducing complexity.
A classic example of this problem in action. I actually encountered this
in real code (of course, this is the distilled example, the real example
was spread out over a few tens of thousands of lines of code):
#include <string>
#include <iostream>
class base {
public:
virtual char * getName(void) = 0;
};
class exA : public base {
public:
char * getName(void) { return "exA"; }
};
class exB : public base {
private:
char * name;
public:
exB() {
name = new char[4];
strcpy(name, "exB");
}
virtual ~exB() { delete[] name; }
char * getName(void) { return name; }
};
class exC : public base {
public:
char * getName(void) {
char * retval = new char[4];
strcpy(retval, "exC");
return retval;
}
};
void breakMe(base * ptr) {
char * name = ptr->getName();
delete ptr;
std::cout << "Object name was \"" << name << "\".\n";
delete[] name;
}
> > Don't assume that inlining is optimization. Actually, it generally isn't.
> > Having actually timed it on modern hardware, a function call costs like
> > 2-3 clock cycles these days. Plus 1-2 clock cycles per argument. This is
> > compared to the 10-30 clock cycles a mispredicted branch costs, the 20+
> > clock cycles an L1 cache miss/L2 cache hit costs, and the 100-350+ clock
> > cycles of an L2 cache miss/memory fetch.
> Inlining for very small functions generally is an optimization.
Very small functions, yes. But it's less of an optimization than people
think, and (especially in C++) it gets way overused.
Allowing the programmer to force some functions to be inlined is right up
there with allowing the programmer to force some variables to be stored in
registers in usefullness.
Brian
next prev parent reply other threads:[~2005-02-12 15:18 UTC|newest]
Thread overview: 169+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-02-02 21:31 Estimating the size of the ocaml community Yaron Minsky
2005-02-02 21:36 ` [Caml-list] " Christopher A. Watford
2005-02-02 21:54 ` Frédéric Gava
2005-02-03 3:58 ` skaller
2005-02-03 6:35 ` Erik de Castro Lopo
2005-02-03 16:29 ` Olivier Pérès
2005-02-03 18:06 ` Thomas Fischbacher
2005-02-03 18:34 ` Frédéric Gava
2005-02-03 21:16 ` Thomas Fischbacher
2005-02-03 21:58 ` Paul Snively
2005-02-03 22:42 ` Bardur Arantsson
2005-02-03 23:29 ` Thomas Fischbacher
2005-02-03 22:33 ` josh
2005-02-03 23:22 ` Thomas Fischbacher
2005-02-03 23:39 ` Richard Jones
2005-02-04 9:04 ` Frédéric Gava
2005-02-04 9:37 ` Richard Jones
2005-02-04 10:11 ` Olivier Andrieu
2005-02-04 11:14 ` Frédéric Gava
2005-02-04 12:15 ` Richard Jones
2005-02-04 12:46 ` Marcin 'Qrczak' Kowalczyk
2005-02-04 12:51 ` Gerd Stolpmann
2005-02-04 13:43 ` Richard W. M. Jones
2005-02-04 16:01 ` Gerd Stolpmann
2005-02-04 16:52 ` Oliver Bandel
2005-02-04 17:21 ` Frédéric Gava
2005-02-04 17:55 ` Oliver Bandel
2005-02-04 16:48 ` Oliver Bandel
2005-02-04 12:15 ` Olivier Andrieu
2005-02-04 16:42 ` Oliver Bandel
2005-02-04 10:58 ` Oliver Bandel
2005-02-04 17:27 ` Damien Doligez
2005-02-04 17:59 ` Oliver Bandel
2005-02-04 1:17 ` Michael Walter
2005-02-04 10:53 ` Oliver Bandel
2005-02-04 22:01 ` Thomas Fischbacher
2005-02-05 12:27 ` Oliver Bandel
2005-02-06 0:08 ` Thomas Fischbacher
2005-02-03 23:29 ` Richard Jones
2005-02-04 2:33 ` Jon Harrop
[not found] ` <877e9a170502031856175260c8@mail.gmail.com>
2005-02-04 2:56 ` Michael Walter
2005-02-04 10:26 ` [Caml-list] The boon of static type checking Jon Harrop
2005-02-04 17:02 ` Damien Doligez
2005-02-04 18:00 ` Jon Harrop
2005-02-04 20:38 ` Christophe TROESTLER
2005-02-04 21:42 ` Jon Harrop
2005-02-04 22:11 ` Christophe TROESTLER
2005-02-05 0:58 ` Jon Harrop
2005-02-05 1:52 ` Shivkumar Chandrasekaran
2005-02-07 18:47 ` Damien Doligez
2005-02-05 5:24 ` Jacques Garrigue
2005-02-04 21:52 ` Thomas Fischbacher
2005-02-04 22:27 ` Christophe TROESTLER
2005-02-05 10:00 ` Remi Vanicat
2005-02-06 11:18 ` Christophe TROESTLER
2005-02-04 22:55 ` Thomas Fischbacher
2005-02-06 0:02 ` Thomas Fischbacher
2005-02-06 0:56 ` Erik de Castro Lopo
2005-02-06 10:03 ` Thomas Fischbacher
2005-02-06 1:34 ` Richard Jones
2005-02-06 2:30 ` Erik de Castro Lopo
2005-02-06 9:54 ` Marcin 'Qrczak' Kowalczyk
2005-02-06 10:05 ` Thomas Fischbacher
2005-02-05 21:48 ` Michael Walter
2005-02-06 10:22 ` Radu Grigore
2005-02-06 12:16 ` Gerd Stolpmann
2005-02-06 14:59 ` skaller
2005-02-06 22:30 ` Radu Grigore
2005-02-07 3:15 ` Erik de Castro Lopo
2005-02-06 17:28 ` Jon
2005-02-06 22:26 ` Radu Grigore
2005-02-07 2:51 ` skaller
2005-02-07 1:54 ` skaller
2005-02-07 5:34 ` Brian Hurt
2005-02-07 6:16 ` Michael Walter
2005-02-07 14:58 ` Igor Pechtchanski
2005-02-12 15:22 ` Brian Hurt [this message]
2005-02-12 16:11 ` Thomas Fischbacher
2005-02-12 18:47 ` Brian Hurt
2005-02-12 21:58 ` Thomas Fischbacher
2005-02-12 17:06 ` skaller
2005-02-12 22:57 ` Michael Walter
2005-02-13 1:12 ` Thomas Fischbacher
2005-02-13 1:51 ` Tony Edgin
2005-02-13 2:12 ` Thomas Fischbacher
2005-02-13 10:26 ` Daniel Heck
2005-02-13 18:28 ` Thomas Fischbacher
2005-02-13 20:52 ` Michael Walter
2005-02-13 21:42 ` Thomas Fischbacher
2005-02-13 22:51 ` Michael Walter
2005-02-13 23:59 ` Thomas Fischbacher
2005-02-14 0:11 ` Michael Walter
2005-02-14 0:42 ` Thomas Fischbacher
2005-02-14 1:11 ` Michael Walter
2005-02-14 1:46 ` Michael Vanier
2005-02-14 1:57 ` Michael Walter
2005-02-14 14:19 ` Stefan Monnier
2005-02-14 14:36 ` [Caml-list] " Thomas Fischbacher
2005-02-14 1:19 ` [Caml-list] " Michael Walter
2005-02-14 17:29 ` Martin Berger
2005-02-14 18:44 ` skaller
2005-02-14 19:17 ` Thomas Fischbacher
2005-02-14 2:22 ` skaller
2005-02-14 8:04 ` Paul Snively
2005-02-14 9:33 ` Thomas Fischbacher
2005-02-14 9:39 ` Thomas Fischbacher
2005-02-14 2:10 ` skaller
2005-02-13 2:27 ` Brian Hurt
2005-02-13 2:34 ` Michael Walter
2005-02-07 10:57 ` Ville-Pertti Keinonen
2005-02-07 16:58 ` skaller
2005-02-07 17:24 ` Ville-Pertti Keinonen
2005-02-07 17:56 ` Paul Snively
2005-02-07 17:59 ` skaller
2005-02-07 17:30 ` skaller
2005-02-07 13:07 ` Marcin 'Qrczak' Kowalczyk
2005-02-12 15:42 ` Brian Hurt
2005-02-07 17:42 ` Ken Rose
2005-02-07 2:23 ` skaller
2005-02-04 9:29 ` [Caml-list] Estimating the size of the ocaml community Thomas Fischbacher
2005-02-04 10:26 ` Andreas Rossberg
2005-02-04 17:54 ` Thomas Fischbacher
2005-02-04 15:43 ` Oliver Bandel
2005-02-04 19:54 ` Christophe TROESTLER
2005-02-04 20:20 ` Karl Zilles
2005-02-04 22:07 ` Thomas Fischbacher
2005-02-04 9:41 ` Richard Jones
2005-02-04 10:03 ` Thomas Fischbacher
2005-02-04 16:00 ` Oliver Bandel
2005-02-04 17:32 ` sejourne_kevin
2005-02-04 18:46 ` Oliver Bandel
2005-02-05 1:49 ` skaller
2005-02-04 8:55 ` Ville-Pertti Keinonen
2005-02-04 9:36 ` Thomas Fischbacher
2005-02-04 10:30 ` Oliver Bandel
2005-02-04 22:02 ` Thomas Fischbacher
2005-02-05 13:14 ` Oliver Bandel
2005-02-05 16:37 ` Why can't types and exceptions be nested (was: Re: [Caml-list] Estimating the size of the ocaml community) Richard Jones
2005-02-05 17:04 ` Basile STARYNKEVITCH
2005-02-05 19:26 ` Oliver Bandel
2005-02-06 2:56 ` skaller
2005-02-04 21:55 ` [Caml-list] Estimating the size of the ocaml community Basile STARYNKEVITCH
2005-02-03 19:04 ` ronniec95
2005-02-03 20:06 ` skaller
2005-02-03 20:50 ` chris.danx
2005-02-03 21:14 ` Jon Harrop
2005-02-03 21:34 ` chris.danx
2005-02-03 22:07 ` Bardur Arantsson
2005-02-03 21:47 ` Nicolas Cannasse
2005-02-04 3:52 ` skaller
2005-02-04 16:12 ` Oliver Bandel
2005-02-05 2:04 ` skaller
2005-02-03 20:35 ` chris.danx
2005-02-03 8:36 ` sejourne_kevin
2005-02-03 8:39 ` Matthieu Brucher
2005-02-03 16:23 ` Olivier Pérès
2005-02-03 10:10 ` Stefano Zacchiroli
2005-02-03 16:44 ` Vincenzo Ciancia
2005-02-02 22:10 ` [Caml-list] " Kenneth Knowles
2005-02-02 22:40 ` Michael Jeffrey Tucker
2005-02-02 22:52 ` Richard Jones
2005-02-02 23:42 ` Nicolas Cannasse
2005-02-03 6:53 ` Evan Martin
2005-02-03 6:57 ` Eric Stokes
2005-02-03 20:53 ` chris.danx
2005-02-03 23:29 ` Sylvain LE GALL
2005-02-03 23:38 ` sejourne_kevin
2005-02-07 8:49 ` Sven Luther
2005-02-07 9:23 ` Johann Spies
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Pine.LNX.4.44.0502120837090.5563-100000@localhost.localdomain \
--to=bhurt@spnz.org \
--cc=caml-list@yquem.inria.fr \
--cc=jdh30@cam.ac.uk \
--cc=michael.walter@gmail.com \
--cc=skaller@users.sourceforge.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox