Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #9589 > unrolled thread

Generally, are the programs written by C++ slower than written by C 10% ?

Started byKaiWen <wenkai1987@gmail.com>
First post2011-09-01 01:41 -0700
Last post2011-09-03 15:11 -0700
Articles 20 on this page of 114 — 22 participants

Back to article view | Back to comp.lang.c++


Contents

  Generally, are the programs written by C++ slower than written by C 10% ? KaiWen <wenkai1987@gmail.com> - 2011-09-01 01:41 -0700
    Re: Generally, are the programs written by C++ slower than written by C   10% ? Ian Collins <ian-news@hotmail.com> - 2011-09-01 21:15 +1200
    Re: Generally, are the programs written by C++ slower than written by C 10% ? "Fred Zwarts \(KVI\)" <F.Zwarts@KVI.nl> - 2011-09-01 11:48 +0200
      Re: Generally, are the programs written by C++ slower than written by C 10% ? Joshua Maurice <joshuamaurice@gmail.com> - 2011-09-01 15:34 -0700
        Re: Generally, are the programs written by C++ slower than written by C 10% ? KaiWen <wenkai1987@gmail.com> - 2011-09-01 19:09 -0700
          Re: Generally, are the programs written by C++ slower than written by   C 10% ? Ian Collins <ian-news@hotmail.com> - 2011-09-02 14:39 +1200
          Re: Generally, are the programs written by C++ slower than written by C 10% ? Krice <paulkp@mbnet.fi> - 2011-09-01 22:33 -0700
          Re: Generally, are the programs written by C++ slower than written by C 10% ? Paavo Helde <myfirstname@osa.pri.ee> - 2011-09-02 01:12 -0500
            Re: Generally, are the programs written by C++ slower than written by C 10% ? James Kanze <james.kanze@gmail.com> - 2011-09-03 15:25 -0700
              Re: Generally, are the programs written by C++ slower than written by C 10% ? Paavo Helde <myfirstname@osa.pri.ee> - 2011-09-04 01:34 -0500
                Re: Generally, are the programs written by C++ slower than written by C 10% ? BGB <cr88192@hotmail.com> - 2011-09-04 02:33 -0700
                Re: Generally, are the programs written by C++ slower than written by C 10% ? James Kanze <james.kanze@gmail.com> - 2011-09-04 11:00 -0700
          Re: Generally, are the programs written by C++ slower than written by C 10% ? Goran <goran.pusic@gmail.com> - 2011-09-01 23:23 -0700
            Re: Generally, are the programs written by C++ slower than written by C 10% ? Nick Keighley <nick_keighley_nospam@hotmail.com> - 2011-09-02 03:00 -0700
              Re: Generally, are the programs written by C++ slower than written by C 10% ? Goran <goran.pusic@gmail.com> - 2011-09-02 09:39 -0700
            Re: Generally, are the programs written by C++ slower than written by C 10% ? Rui Maciel <rui.maciel@gmail.com> - 2011-09-02 12:44 +0100
          Re: Generally, are the programs written by C++ slower than written by C 10% ? Rui Maciel <rui.maciel@gmail.com> - 2011-09-02 09:59 +0100
            Re: Generally, are the programs written by C++ slower than written by C 10% ? BGB <cr88192@hotmail.com> - 2011-09-02 11:25 -0700
          Re: Generally, are the programs written by C++ slower than written by C 10% ? Juha Nieminen <nospam@thanks.invalid> - 2011-09-03 05:51 +0000
            Re: Generally, are the programs written by C++ slower than written by C 10% ? BGB <cr88192@hotmail.com> - 2011-09-03 01:45 -0700
              Re: Generally, are the programs written by C++ slower than written   by C 10% ? Ian Collins <ian-news@hotmail.com> - 2011-09-03 20:53 +1200
                Re: Generally, are the programs written by C++ slower than written   by C 10% ? BGB <cr88192@hotmail.com> - 2011-09-03 10:49 -0700
                  Re: Generally, are the programs written by C++ slower than written     by C 10% ? Ian Collins <ian-news@hotmail.com> - 2011-09-04 08:15 +1200
                    Re: Generally, are the programs written by C++ slower than written     by C 10% ? BGB <cr88192@hotmail.com> - 2011-09-03 17:50 -0700
              Re: Generally, are the programs written by C++ slower than written by C 10% ? Juha Nieminen <nospam@thanks.invalid> - 2011-09-03 16:28 +0000
                Re: Generally, are the programs written by C++ slower than written by C 10% ? BGB <cr88192@hotmail.com> - 2011-09-03 10:42 -0700
                  Re: Generally, are the programs written by C++ slower than written by C 10% ? "Bo Persson" <bop@gmb.dk> - 2011-09-04 11:34 +0200
                    Re: Generally, are the programs written by C++ slower than written by C 10% ? BGB <cr88192@hotmail.com> - 2011-09-04 09:04 -0700
                  Re: Generally, are the programs written by C++ slower than written by C 10% ? Juha Nieminen <nospam@thanks.invalid> - 2011-09-04 18:04 +0000
                    Re: Generally, are the programs written by C++ slower than written by C 10% ? Keith H Duggar <duggar@alum.mit.edu> - 2011-09-04 18:44 -0700
                    Re: Generally, are the programs written by C++ slower than written by C 10% ? BGB <cr88192@hotmail.com> - 2011-09-04 23:26 -0700
                      Re: Generally, are the programs written by C++ slower than written by C 10% ? Juha Nieminen <nospam@thanks.invalid> - 2011-09-05 08:01 +0000
                        Re: Generally, are the programs written by C++ slower than written by C 10% ? BGB <cr88192@hotmail.com> - 2011-09-05 11:45 -0700
                          Re: Generally, are the programs written by C++ slower than written by C 10% ? Juha Nieminen <nospam@thanks.invalid> - 2011-09-06 06:30 +0000
                            Re: Generally, are the programs written by C++ slower than written by C 10% ? BGB <cr88192@hotmail.com> - 2011-09-06 07:22 -0700
                          Re: Generally, are the programs written by C++ slower than written by C 10% ? Miles Bader <miles@gnu.org> - 2011-09-06 16:25 +0900
                            Re: Generally, are the programs written by C++ slower than written by C 10% ? BGB <cr88192@hotmail.com> - 2011-09-06 07:14 -0700
                              Re: Generally, are the programs written by C++ slower than written by C 10% ? Miles Bader <miles@gnu.org> - 2011-09-07 12:28 +0900
                                Re: Generally, are the programs written by C++ slower than written by C 10% ? BGB <cr88192@hotmail.com> - 2011-09-07 16:49 -0700
                                  Re: Generally, are the programs written by C++ slower than written by C 10% ? Noah Roberts <roberts.noah@gmail.com> - 2011-09-07 18:45 -0700
                                    Re: Generally, are the programs written by C++ slower than written by C 10% ? BGB <cr88192@hotmail.com> - 2011-09-08 15:56 -0700
              Re: Generally, are the programs written by C++ slower than written by C 10% ? James Kanze <james.kanze@gmail.com> - 2011-09-03 15:32 -0700
                Re: Generally, are the programs written by C++ slower than written by C 10% ? BGB <cr88192@hotmail.com> - 2011-09-03 19:16 -0700
              Re: Generally, are the programs written by C++ slower than written by C 10% ? Nick Keighley <nick_keighley_nospam@hotmail.com> - 2011-09-05 00:28 -0700
                Re: Generally, are the programs written by C++ slower than written by C 10% ? BGB <cr88192@hotmail.com> - 2011-09-05 12:34 -0700
                  Re: Generally, are the programs written by C++ slower than written   by C 10% ? Ian Collins <ian-news@hotmail.com> - 2011-09-06 07:51 +1200
                    Re: Generally, are the programs written by C++ slower than written   by C 10% ? BGB <cr88192@hotmail.com> - 2011-09-05 14:06 -0700
                      Re: Generally, are the programs written by C++ slower than written by C 10% ? Nick Keighley <nick_keighley_nospam@hotmail.com> - 2011-09-06 00:32 -0700
                        Re: Generally, are the programs written by C++ slower than written by C 10% ? BGB <cr88192@hotmail.com> - 2011-09-06 07:33 -0700
                          Re: Generally, are the programs written by C++ slower than written by C 10% ? Nick Keighley <nick_keighley_nospam@hotmail.com> - 2011-09-07 02:52 -0700
                            Re: Generally, are the programs written by C++ slower than written by C 10% ? BGB <cr88192@hotmail.com> - 2011-09-08 16:24 -0700
                              Re: Generally, are the programs written by C++ slower than written   by C 10% ? Ian Collins <ian-news@hotmail.com> - 2011-09-09 11:38 +1200
                                Re: Generally, are the programs written by C++ slower than written   by C 10% ? BGB <cr88192@hotmail.com> - 2011-09-08 21:39 -0700
                                  Re: Generally, are the programs written by C++ slower than written     by C 10% ? Ian Collins <ian-news@hotmail.com> - 2011-09-09 19:01 +1200
                                    Re: Generally, are the programs written by C++ slower than written     by C 10% ? BGB <cr88192@hotmail.com> - 2011-09-09 02:45 -0700
                                    Re: Generally, are the programs written by C++ slower than written by C 10% ? Nick Keighley <nick_keighley_nospam@hotmail.com> - 2011-09-09 03:23 -0700
                                    Re: Generally, are the programs written by C++ slower than written     by C 10% ? Jorgen Grahn <grahn+nntp@snipabacken.se> - 2011-09-14 23:12 +0000
                              Re: Generally, are the programs written by C++ slower than written by C 10% ? Nick Keighley <nick_keighley_nospam@hotmail.com> - 2011-09-09 02:40 -0700
                                Re: Generally, are the programs written by C++ slower than written by C 10% ? BGB <cr88192@hotmail.com> - 2011-09-09 11:19 -0700
                                  Re: Generally, are the programs written by C++ slower than written by C 10% ? Paavo Helde <myfirstname@osa.pri.ee> - 2011-09-09 15:42 -0500
                                    Re: Generally, are the programs written by C++ slower than written by C 10% ? BGB <cr88192@hotmail.com> - 2011-09-09 14:24 -0700
                                      Re: Generally, are the programs written by C++ slower than written by C 10% ? Noah Roberts <roberts.noah@gmail.com> - 2011-09-09 18:22 -0700
                                        Re: Generally, are the programs written by C++ slower than written by C 10% ? BGB <cr88192@hotmail.com> - 2011-09-10 10:11 -0700
                                          Re: Generally, are the programs written by C++ slower than written by C 10% ? Noah Roberts <roberts.noah@gmail.com> - 2011-09-10 10:54 -0700
                                            Re: Generally, are the programs written by C++ slower than written by C 10% ? BGB <cr88192@hotmail.com> - 2011-09-10 14:28 -0700
                                              Re: Generally, are the programs written by C++ slower than written by C 10% ? Miles Bader <miles@gnu.org> - 2011-09-11 12:29 +0900
                                                Re: Generally, are the programs written by C++ slower than written by C 10% ? BGB <cr88192@hotmail.com> - 2011-09-11 00:45 -0700
                                                Re: Generally, are the programs written by C++ slower than written by C 10% ? Joshua Maurice <joshuamaurice@gmail.com> - 2011-09-12 00:39 -0700
                                                  Re: Generally, are the programs written by C++ slower than written by C 10% ? Miles Bader <miles@gnu.org> - 2011-09-12 18:06 +0900
                                                    Re: Generally, are the programs written by C++ slower than written by C 10% ? Joshua Maurice <joshuamaurice@gmail.com> - 2011-09-12 16:46 -0700
                                                      Re: Generally, are the programs written by C++ slower than written by C 10% ? Miles Bader <miles@gnu.org> - 2011-09-13 10:20 +0900
                                                        Re: Generally, are the programs written by C++ slower than written by C 10% ? Joshua Maurice <joshuamaurice@gmail.com> - 2011-09-13 13:16 -0700
                                              Re: Generally, are the programs written by C++ slower than written by C 10% ? Nobody <nobody@nowhere.com> - 2011-09-11 04:53 +0100
                                                Re: Generally, are the programs written by C++ slower than written by C 10% ? Miles Bader <miles@gnu.org> - 2011-09-11 14:51 +0900
                                  Re: Generally, are the programs written by C++ slower than written by C 10% ? Nick Keighley <nick_keighley_nospam@hotmail.com> - 2011-09-10 07:46 -0700
                    Re: Generally, are the programs written by C++ slower than written by C 10% ? KaiWen <wenkai1987@gmail.com> - 2011-09-06 03:10 -0700
                      Re: Generally, are the programs written by C++ slower than written by   C 10% ? Ian Collins <ian-news@hotmail.com> - 2011-09-06 22:50 +1200
                        Re: Generally, are the programs written by C++ slower than written by C 10% ? KaiWen <wenkai1987@gmail.com> - 2011-09-06 04:48 -0700
                          Re: Generally, are the programs written by C++ slower than written by C 10% ? yatremblay@bel1lin202.(none) (Yannick Tremblay) - 2011-09-07 09:45 +0000
                            Re: Generally, are the programs written by C++ slower than written by   C 10% ? Ian Collins <ian-news@hotmail.com> - 2011-09-07 21:51 +1200
                            Re: Generally, are the programs written by C++ slower than written by C 10% ? KaiWen <wenkai1987@gmail.com> - 2011-09-08 00:15 -0700
                              Re: Generally, are the programs written by C++ slower than written by C 10% ? yatremblay@bel1lin202.(none) (Yannick Tremblay) - 2011-09-08 12:14 +0000
                                Re: Generally, are the programs written by C++ slower than written by C 10% ? KaiWen <wenkai1987@gmail.com> - 2011-09-08 07:14 -0700
                        Re: Generally, are the programs written by C++ slower than written by C 10% ? Asger-P <junk@asger-p.dk> - 2011-09-06 13:52 +0200
                      Re: Generally, are the programs written by C++ slower than written by C 10% ? Paavo Helde <myfirstname@osa.pri.ee> - 2011-09-06 11:47 -0500
                        Re: Generally, are the programs written by C++ slower than written by C 10% ? Paavo Helde <myfirstname@osa.pri.ee> - 2011-09-06 11:50 -0500
                        Re: Generally, are the programs written by C++ slower than written by C 10% ? Asger-P <junk@asger-p.dk> - 2011-09-06 21:04 +0200
                          Re: Generally, are the programs written by C++ slower than written by C 10% ? Leigh Johnston <leigh@i42.co.uk> - 2011-09-06 20:37 +0100
                            Re: Generally, are the programs written by C++ slower than written by C 10% ? Paavo Helde <myfirstname@osa.pri.ee> - 2011-09-06 15:10 -0500
                              Re: Generally, are the programs written by C++ slower than written by C 10% ? Leigh Johnston <leigh@i42.co.uk> - 2011-09-06 21:14 +0100
                              Re: Generally, are the programs written by C++ slower than written by C 10% ? Asger-P <junk@asger-p.dk> - 2011-09-07 00:40 +0200
                                Re: Generally, are the programs written by C++ slower than written by C 10% ? Leigh Johnston <leigh@i42.co.uk> - 2011-09-06 23:59 +0100
                                Re: Generally, are the programs written by C++ slower than written by C 10% ? Noah Roberts <roberts.noah@gmail.com> - 2011-09-06 16:26 -0700
                          Re: Generally, are the programs written by C++ slower than written by C 10% ? Paavo Helde <myfirstname@osa.pri.ee> - 2011-09-06 14:55 -0500
                            Re: Generally, are the programs written by C++ slower than written by C 10% ? Asger-P <junk@asger-p.dk> - 2011-09-07 00:51 +0200
                              Re: Generally, are the programs written by C++ slower than written by C 10% ? Paavo Helde <myfirstname@osa.pri.ee> - 2011-09-06 23:29 -0500
                                Re: Generally, are the programs written by C++ slower than written by C 10% ? Asger-P <junk@asger-p.dk> - 2011-09-07 09:06 +0200
                                  Re: Generally, are the programs written by C++ slower than written by   C 10% ? Ian Collins <ian-news@hotmail.com> - 2011-09-07 19:09 +1200
                                  Re: Generally, are the programs written by C++ slower than written by C 10% ? Nobody <nobody@nowhere.com> - 2011-09-07 13:19 +0100
                                    Re: Generally, are the programs written by C++ slower than written by C 10% ? Juha Nieminen <nospam@thanks.invalid> - 2011-09-07 13:01 +0000
                                  Re: Generally, are the programs written by C++ slower than written by C 10% ? Rui Maciel <rui.maciel@gmail.com> - 2011-09-07 14:26 +0100
                                    Re: Generally, are the programs written by C++ slower than written by C 10% ? Asger-P <junk@asger-p.dk> - 2011-09-07 15:49 +0200
                                  Re: Generally, are the programs written by C++ slower than written by C 10% ? BGB <cr88192@hotmail.com> - 2011-09-08 22:49 -0700
                                    Re: Generally, are the programs written by C++ slower than written by C 10% ? Miles Bader <miles@gnu.org> - 2011-09-09 15:25 +0900
                                      Re: Generally, are the programs written by C++ slower than written by C 10% ? BGB <cr88192@hotmail.com> - 2011-09-09 02:50 -0700
                                        Re: Generally, are the programs written by C++ slower than written by C 10% ? Nick Keighley <nick_keighley_nospam@hotmail.com> - 2011-09-09 03:26 -0700
                                      Re: Generally, are the programs written by C++ slower than written by C 10% ? Nick Keighley <nick_keighley_nospam@hotmail.com> - 2011-09-09 03:25 -0700
                  Re: Generally, are the programs written by C++ slower than written by C 10% ? Nick Keighley <nick_keighley_nospam@hotmail.com> - 2011-09-06 00:24 -0700
              Re: Generally, are the programs written by C++ slower than written by C 10% ? yatremblay@bel1lin202.(none) (Yannick Tremblay) - 2011-09-06 13:57 +0000
                Re: Generally, are the programs written by C++ slower than written by C 10% ? BGB <cr88192@hotmail.com> - 2011-09-06 08:18 -0700
          Re: Generally, are the programs written by C++ slower than written by C 10% ? Nobody <nobody@nowhere.com> - 2011-09-03 08:34 +0100
    Re: Generally, are the programs written by C++ slower than written by C 10% ? "A" <a@a.a> - 2011-09-01 11:50 +0200
    Re: Generally, are the programs written by C++ slower than written by C 10% ? Rui Maciel <rui.maciel@gmail.com> - 2011-09-01 10:53 +0100
    Re: Generally, are the programs written by C++ slower than written by C 10% ? James Kanze <james.kanze@gmail.com> - 2011-09-03 15:11 -0700

Page 1 of 6  [1] 2 3 4 5 6  Next page →


#9589 — Generally, are the programs written by C++ slower than written by C 10% ?

FromKaiWen <wenkai1987@gmail.com>
Date2011-09-01 01:41 -0700
SubjectGenerally, are the programs written by C++ slower than written by C 10% ?
Message-ID<c5892d85-95b2-4e19-a11c-cde621a9ab4c@r40g2000prf.googlegroups.com>
Generally, are the programs written by C++ slower than written by C
10% ?

[toc] | [next] | [standalone]


#9590 — Re: Generally, are the programs written by C++ slower than written by C 10% ?

FromIan Collins <ian-news@hotmail.com>
Date2011-09-01 21:15 +1200
SubjectRe: Generally, are the programs written by C++ slower than written by C 10% ?
Message-ID<9c90q1Fpb9U1@mid.individual.net>
In reply to#9589
On 09/ 1/11 08:41 PM, KaiWen wrote:
> Generally, are the programs written by C++ slower than written by C
> 10% ?

No, assuming you intended to write in rather than by...

-- 
Ian Collins

[toc] | [prev] | [next] | [standalone]


#9592

From"Fred Zwarts \(KVI\)" <F.Zwarts@KVI.nl>
Date2011-09-01 11:48 +0200
Message-ID<j3nkd9$r1u$1@news.albasani.net>
In reply to#9589
"KaiWen"  wrote in message 
news:c5892d85-95b2-4e19-a11c-cde621a9ab4c@r40g2000prf.googlegroups.com...

> Generally, are the programs written by C++ slower than written by C 10% ?

It is not clear to me what you mean.
C++ is more complicated than C, so C++ programs are written somewhat slower 
that C programs, because more thinking is needed. But, at the other hand, 
C++ usually needs less source code to complete a complex program (because of 
the availability of a rich library and the reuse of code in templates), so 
writing a program may be completed faster in C++ that in C. 

[toc] | [prev] | [next] | [standalone]


#9624

FromJoshua Maurice <joshuamaurice@gmail.com>
Date2011-09-01 15:34 -0700
Message-ID<d403d37c-2bfe-4cbe-b97e-493e3d9ae25c@t20g2000prf.googlegroups.com>
In reply to#9592
On Sep 1, 2:48 am, "Fred Zwarts \(KVI\)" <F.Zwa...@KVI.nl> wrote:
> "KaiWen"  wrote in message
>
> news:c5892d85-95b2-4e19-a11c-cde621a9ab4c@r40g2000prf.googlegroups.com...
>
> > Generally, are the programs written by C++ slower than written by C 10% ?
>
> It is not clear to me what you mean.
> C++ is more complicated than C, so C++ programs are written somewhat slower
> that C programs, because more thinking is needed. But, at the other hand,
> C++ usually needs less source code to complete a complex program (because of
> the availability of a rich library and the reuse of code in templates), so
> writing a program may be completed faster in C++ that in C.

Do you have any reliable evidence to make such a claim? I believe this
is a complete pull out of thin air without any supporting evidence.
I'll add my own pull out of thin air and claim that this is a non-
obvious claim.

I'll go even further actually. As long as the C++ constructs can map
nicely to "equivalent" C constructs, I see no reason why C++ programs
will be slower with a good compiler. It depends heavily on the exact
programs. Usually people make unfair apples-to-oranges comparisons of
an OO approach vs a procedural approach. When doing legitimate
comparisons, you will find the C and C++ program are much closer than
you think.

[toc] | [prev] | [next] | [standalone]


#9640

FromKaiWen <wenkai1987@gmail.com>
Date2011-09-01 19:09 -0700
Message-ID<fa40b251-1e2d-49f1-8d52-af2bf47fbc30@p37g2000prp.googlegroups.com>
In reply to#9624
On 9月2日, 上午6时34分, Joshua Maurice <joshuamaur...@gmail.com> wrote:
> On Sep 1, 2:48 am, "Fred Zwarts \(KVI\)" <F.Zwa...@KVI.nl> wrote:
>
> > "KaiWen"  wrote in message
>
> >news:c5892d85-95b2-4e19-a11c-cde621a9ab4c@r40g2000prf.googlegroups.com...
>
> > > Generally, are the programs written by C++ slower than written by C 10% ?
>
> > It is not clear to me what you mean.
> > C++ is more complicated than C, so C++ programs are written somewhat slower
> > that C programs, because more thinking is needed. But, at the other hand,
> > C++ usually needs less source code to complete a complex program (because of
> > the availability of a rich library and the reuse of code in templates), so
> > writing a program may be completed faster in C++ that in C.
>
> Do you have any reliable evidence to make such a claim? I believe this
> is a complete pull out of thin air without any supporting evidence.
> I'll add my own pull out of thin air and claim that this is a non-
> obvious claim.
>
> I'll go even further actually. As long as the C++ constructs can map
> nicely to "equivalent" C constructs, I see no reason why C++ programs
> will be slower with a good compiler. It depends heavily on the exact
> programs. Usually people make unfair apples-to-oranges comparisons of
> an OO approach vs a procedural approach. When doing legitimate
> comparisons, you will find the C and C++ program are much closer than
> you think.

We don't discuss OO here, just discuss the cost of compile time and
the speed of program.
1. Compile a C++ program is slower than written by C
2. In runtime, the speed of the program written by C++ is <= the same
   program written by C

I want to write a program about network, parse huge number of data,
so, with all due respect, I can not decide witch language to use.

I know I can develop faster by using C++, but the speed of program
in runtime is important too. So witch one is important? Can anyone
give a suggestion?

[toc] | [prev] | [next] | [standalone]


#9641 — Re: Generally, are the programs written by C++ slower than written by C 10% ?

FromIan Collins <ian-news@hotmail.com>
Date2011-09-02 14:39 +1200
SubjectRe: Generally, are the programs written by C++ slower than written by C 10% ?
Message-ID<9catubFvoqU1@mid.individual.net>
In reply to#9640
On 09/ 2/11 02:09 PM, KaiWen wrote:
> 
> I want to write a program about network, parse huge number of data,
> so, with all due respect, I can not decide witch language to use.
> 
> I know I can develop faster by using C++, but the speed of program
> in runtime is important too. So witch one is important? Can anyone
> give a suggestion?

A poor choice of algorithm will run just as slow in well written C as in
well written C++.

A good choice of algorithm will run just as fast in well written C++
(and maybe faster if generic code such as sort is used) as in well
written C.

-- 
Ian Collins

[toc] | [prev] | [next] | [standalone]


#9644

FromKrice <paulkp@mbnet.fi>
Date2011-09-01 22:33 -0700
Message-ID<9d796edc-806f-4832-9afe-918267f4f0e8@x2g2000yql.googlegroups.com>
In reply to#9640
On 2 syys, 05:09, KaiWen <wenkai1...@gmail.com> wrote:
> but the speed of program in runtime is important too.

The speed depends on programming skills more than small
differences between C and C++.

[toc] | [prev] | [next] | [standalone]


#9646

FromPaavo Helde <myfirstname@osa.pri.ee>
Date2011-09-02 01:12 -0500
Message-ID<Xns9F545DB9C66F7myfirstnameosapriee@216.196.109.131>
In reply to#9640
KaiWen <wenkai1987@gmail.com> wrote in
news:fa40b251-1e2d-49f1-8d52-af2bf47fbc30@p37g2000prp.googlegroups.com: 

>> > > Generally, are the programs written by C++ slower than written by
>> > > C 1 
> 0% ?
> 
> We don't discuss OO here, just discuss the cost of compile time and
> the speed of program.
> 1. Compile a C++ program is slower than written by C

Depends on the programming style, but in general this tends to be true. 
Especially compiling heavily templated code is typically quite slow.

> 2. In runtime, the speed of the program written by C++ is <= the same
>    program written by C

This does not follow. Both languages are Turing complete and apply the 
"do-not-pay-for-what's-not-used" policy, so if some program+input data 
combination happens to be slower in one language on some platform, one 
can always tune the code until the performance is the same. For example, 
if the C variant is slower because of using qsort() instead of std::sort
(), one can replace qsort() calls with an inlined sort algorithm 
implementation. Or if the frequent string length calculation and dynamic 
allocation of small strings appears to be a bottleneck in a C program, 
one can always design ones' own string struct type in C, recording the 
length and using small string optimization, effectively reproducing C++ 
std::string.

The question is just how much effort must be spent in a typical program 
to achieve good performance.

> 
> I want to write a program about network, parse huge number of data,
> so, with all due respect, I can not decide witch language to use.
> 
> I know I can develop faster by using C++, but the speed of program
> in runtime is important too. So witch one is important? Can anyone
> give a suggestion?

For writing fast code in C++ one must be quite familiar with the language 
so that one knows what's going on under the hood. The goal is to write 
fast code without sacrifizing the safety and high level abstractions 
possible in C++. It is easy to slip through mistakes which cause unneeded 
data copies or cause multiple passes over the data, or apply virtual 
dispatch in some deep loop, or fail to call .reserve() functions when 
appropriate. Templates and C++0x rvalue references are also often useful 
for writing fast code.

If there is some such mistake, the C++ code will typically be slower than 
ideal, but there is a good chance that it works correctly.

Writing fast code in C is in principle easier as there are fewer high 
level constructs which could potentially cause slowdowns. OTOH, it 
involves all the same C pitfalls as ever, fast code means typically a lot 
of pointer passing in C, so extreme care must be taken over the ownership 
and lifetime of the data. It is easy to produce memory leaks, buffer 
overruns and invalid memory accesses. If there is some such mistake, the 
code will typically run very fast, but works incorrectly or crashes.

So, to give some concrete suggestions:

Large program, good C++ skills: use C++.
Small program, bad C++ skills: use C.
Large program, bad C++ skills: screwed both ways, use C++ to get a slow 
and working program.
Small program, good C++ skills: doesn't matter, use C++ for convenience.

cheers
Paavo





 

[toc] | [prev] | [next] | [standalone]


#9711

FromJames Kanze <james.kanze@gmail.com>
Date2011-09-03 15:25 -0700
Message-ID<ca8f2f18-4f33-464e-9ec6-5519d4914d70@dl2g2000vbb.googlegroups.com>
In reply to#9646
On Sep 2, 7:12 am, Paavo Helde <myfirstn...@osa.pri.ee> wrote:
> KaiWen <wenkai1...@gmail.com> wrote
> innews:fa40b251-1e2d-49f1-8d52-af2bf47fbc30@p37g2000prp.googlegroups.com:

> >> > > Generally, are the programs written by C++ slower than written by
> >> > > C 1
> > 0% ?

    [...]
> > 2. In runtime, the speed of the program written by C++ is <= the same
> >    program written by C

> This does not follow. Both languages are Turing complete and apply the
> "do-not-pay-for-what's-not-used" policy, so if some program+input data
> combination happens to be slower in one language on some platform, one
> can always tune the code until the performance is the same.

Not necessarily, at least not practically.  Tuning often
involves modifications in the data structures, and unless the
variables involved are private, the amount of work involved
generally makes the tuning impractical.  If there's any chance
that performance will be an issue, you almost have to use C++,
rather than C, because it is very, very difficult to tune C.

    [...]
> For writing fast code in C++ one must be quite familiar with
> the language so that one knows what's going on under the hood.

Yes and no.  Most of the time, the largest speed gains are
achieved by using a different algorithm (which may require
diffrerent data structures to support it), or by caching data
(which, of course, only works if all accesses to the data go
through specified functions).  Neither of these require any real
knowledge of what's going on under the hood.

> Writing fast code in C is in principle easier as there are fewer high
> level constructs which could potentially cause slowdowns.

Writing fast code in C is significantly harder, because of the
lack of encapsulation.

    [...]
> So, to give some concrete suggestions:

> Large program, good C++ skills: use C++.
> Small program, bad C++ skills: use C.
> Large program, bad C++ skills: screwed both ways, use C++ to get a slow
> and working program.
> Small program, good C++ skills: doesn't matter, use C++ for convenience.

I'd say:

    Speed important: use C++, regardless of the size.
    Speed not important, large program: use C++.
    Speed not important, (very) small program: use a more dynamic
language,
                                               like Python.

Other issues may also be involved: C++ (used correctly) is far
more robust than most of the readily available alternatives, for
example; for a critical application, it's certainly preferrable
to C (or to Python, or to Java).

As for the level of C++ skills: if the solution is to use C++,
and you have bad C++ skills, improve them.  It's better to take
the time to learn C++ correctly than to use a less appropriate
language.

--
James Kanze

[toc] | [prev] | [next] | [standalone]


#9722

FromPaavo Helde <myfirstname@osa.pri.ee>
Date2011-09-04 01:34 -0500
Message-ID<Xns9F56615C53C01myfirstnameosapriee@216.196.109.131>
In reply to#9711
James Kanze <james.kanze@gmail.com> wrote in
news:ca8f2f18-4f33-464e-9ec6-5519d4914d70@dl2g2000vbb.googlegroups.com: 

> On Sep 2, 7:12 am, Paavo Helde <myfirstn...@osa.pri.ee> wrote:
>> KaiWen <wenkai1...@gmail.com> wrote
>> innews:fa40b251-1e2d-49f1-8d52-af2bf47fbc30@p37g2000prp.googlegroups.c
>> om: 
> 
>> >> > > Generally, are the programs written by C++ slower than written
>> >> > > by C 1
>> > 0% ?
> 
>     [...]
>> > 2. In runtime, the speed of the program written by C++ is <= the
>> > same 
>> >    program written by C
> 
>> This does not follow. Both languages are Turing complete and apply
>> the "do-not-pay-for-what's-not-used" policy, so if some program+input
>> data combination happens to be slower in one language on some
>> platform, one can always tune the code until the performance is the
>> same. 
> 
> Not necessarily, at least not practically.  Tuning often
> involves modifications in the data structures, and unless the
> variables involved are private, the amount of work involved
> generally makes the tuning impractical.  If there's any chance
> that performance will be an issue, you almost have to use C++,
> rather than C, because it is very, very difficult to tune C.

I agree that tuning C code could easily mean rewriting large parts of the 
program. Yet this can be done if the program is small. If it is practical 
or not is another question.

> 
>     [...]
>> For writing fast code in C++ one must be quite familiar with
>> the language so that one knows what's going on under the hood.
> 
> Yes and no.  Most of the time, the largest speed gains are
> achieved by using a different algorithm (which may require
> diffrerent data structures to support it), or by caching data
> (which, of course, only works if all accesses to the data go
> through specified functions).  Neither of these require any real
> knowledge of what's going on under the hood.

Passing a STL container to a function by a copy instead of a reference or 
using a copy where swap() would work - these are easy mistakes to make 
and would qualify as a change in the algorithm (O(1)->O(N)). If one is 
doing this all over the place, the profiler might not even bring it out 
in non-critical paths, meaning that all the code would be just somewhat 
slower than necessary. 

OTOH, in C it takes some extra effort to pass an array into a function by 
copy, so nobody would do this accidentally.

> 
>> Writing fast code in C is in principle easier as there are fewer high
>> level constructs which could potentially cause slowdowns.
> 
> Writing fast code in C is significantly harder, because of the
> lack of encapsulation.

Only if one tries to emulate encapsulation by using means of non-zero 
runtime cost, like dynamically allocated data structures accessed via 
opaque pointers. If one does not attempt to have any encapsulation, then 
there is nothing which would get in the way of having fast code. Of 
course, ensuring that this fast code is also *correct* and *robust* and 
*maintainable* is significantly harder in C, unless the project is really 
small.

cheers
Paavo


[toc] | [prev] | [next] | [standalone]


#9725

FromBGB <cr88192@hotmail.com>
Date2011-09-04 02:33 -0700
Message-ID<j3vglb$lj6$1@news.albasani.net>
In reply to#9722
On 9/3/2011 11:34 PM, Paavo Helde wrote:
> James Kanze<james.kanze@gmail.com>  wrote in
> news:ca8f2f18-4f33-464e-9ec6-5519d4914d70@dl2g2000vbb.googlegroups.com:
>
>> On Sep 2, 7:12 am, Paavo Helde<myfirstn...@osa.pri.ee>  wrote:
>>> KaiWen<wenkai1...@gmail.com>  wrote
>>> innews:fa40b251-1e2d-49f1-8d52-af2bf47fbc30@p37g2000prp.googlegroups.c
>>> om:
>>
>>>>>>> Generally, are the programs written by C++ slower than written
>>>>>>> by C 1
>>>> 0% ?
>>
>>      [...]
>>>> 2. In runtime, the speed of the program written by C++ is<= the
>>>> same
>>>>     program written by C
>>
>>> This does not follow. Both languages are Turing complete and apply
>>> the "do-not-pay-for-what's-not-used" policy, so if some program+input
>>> data combination happens to be slower in one language on some
>>> platform, one can always tune the code until the performance is the
>>> same.
>>
>> Not necessarily, at least not practically.  Tuning often
>> involves modifications in the data structures, and unless the
>> variables involved are private, the amount of work involved
>> generally makes the tuning impractical.  If there's any chance
>> that performance will be an issue, you almost have to use C++,
>> rather than C, because it is very, very difficult to tune C.
>
> I agree that tuning C code could easily mean rewriting large parts of the
> program. Yet this can be done if the program is small. If it is practical
> or not is another question.
>

a lot depends on how code is structured and organized as well...


>>
>>      [...]
>>> For writing fast code in C++ one must be quite familiar with
>>> the language so that one knows what's going on under the hood.
>>
>> Yes and no.  Most of the time, the largest speed gains are
>> achieved by using a different algorithm (which may require
>> diffrerent data structures to support it), or by caching data
>> (which, of course, only works if all accesses to the data go
>> through specified functions).  Neither of these require any real
>> knowledge of what's going on under the hood.
>
> Passing a STL container to a function by a copy instead of a reference or
> using a copy where swap() would work - these are easy mistakes to make
> and would qualify as a change in the algorithm (O(1)->O(N)). If one is
> doing this all over the place, the profiler might not even bring it out
> in non-critical paths, meaning that all the code would be just somewhat
> slower than necessary.
>
> OTOH, in C it takes some extra effort to pass an array into a function by
> copy, so nobody would do this accidentally.
>

yep.

depending as well on how things are structured, one can often change the 
algorithms used internally without impacting its interface.


>>
>>> Writing fast code in C is in principle easier as there are fewer high
>>> level constructs which could potentially cause slowdowns.
>>
>> Writing fast code in C is significantly harder, because of the
>> lack of encapsulation.
>
> Only if one tries to emulate encapsulation by using means of non-zero
> runtime cost, like dynamically allocated data structures accessed via
> opaque pointers. If one does not attempt to have any encapsulation, then
> there is nothing which would get in the way of having fast code. Of
> course, ensuring that this fast code is also *correct* and *robust* and
> *maintainable* is significantly harder in C, unless the project is really
> small.
>

agreed.

however, it is worth nothing that C and C++ better lend themselves to, 
and thus traditionally use, notably different ways of achieving abstraction.

one language is not the other.


C++ more traditionally uses structural abstractions (templates being a 
major example, also classes), where basically one has "something" which 
can be interacted with, but hides its internal workings from view.

these common structures are then often shared over large portions of the 
codebase, and it is assumed that some level of commonality is achieved 
by consistent use of the same structures and abstractions across much of 
the program.

hence, code reuse and uniformity are somewhat emphasized in this style.


C more traditionally is abstracted regionally, more like a large number 
of brick-walled cities. all sorts of things can happen within a given 
set of walls, and what happens outside is "none of anyone's business" 
(typically, at any particular location, the level of abstraction is 
fairly low, with bit-twiddling and mucking around with pointers and 
pointer-arithmetic being "the business of the day").

typically, at the high-level, abstraction is achieved by essentially 
enforcing these walls, and limiting or prohibiting interactions between 
disparate systems ("action at a distance").

typically, this is done at a much coarser level than in traditional OOP 
(say, an individual component could be easily anywhere from 10 to 50 kloc).


even though similar algorithms/... may be used in different places, it 
is usually against-policy to access them directly, and in-fact it is 
more common to simply copy/paste/edit the code into the new location, 
specifically as this will avoid creating a dependency between otherwise 
unrelated components (any such dependency may limit the ability for one 
part to be changed independent of the other, compromising flexibility).

so, typically components are only allowed to directly interact with 
"adjacent" components, and usually then "through a brick wall" (a set of 
public API functions).

often, OS facilities are fit into the model in roughly a similar manner, 
so code in one place may be allowed to use certain OS facilities, and in 
another place, doing so will be forbidden.

which data-types, API calls, ... will also depend very much on where the 
code is located (every city has, to a large extent, its own local rules 
and customs, which may be strictly enforced).


other cases, where a more fluid structuring is needed, typically one may 
have APIs which simply serve to redirect somewhere else or to something 
else (basically, APIs serving a role mostly to ease communication 
between components while at the same time attempting to avoid 
compromising borders).

typically the goal of such an API is to provide a common interface to 
functionality exposed by several different components. however, its own 
local conventions are unique to itself (and similar rules apply as 
before, it itself may be subject to only being allowed in certain code 
regions).

sometimes, the combinations of the above may lead to a certain amount of 
indirection (FWIW, interface-routing APIs, namely exposing an API to 
allow certain functionality in a region of code where otherwise it would 
not have been allowed).

...



but, these differences may lead to very different views WRT things like 
ideal system architecture and development practices.

I don't personally believe any of this to be matters of "good" vs "bad" 
(or "competent" vs "incompetent", or "smart" vs "stupid") or anything of 
the sort, rather, the ultimate higher goal is "what works best in a 
given situation".


or such...

[toc] | [prev] | [next] | [standalone]


#9737

FromJames Kanze <james.kanze@gmail.com>
Date2011-09-04 11:00 -0700
Message-ID<1adbc6c4-b567-4e6c-affe-b8dc7100cbaa@j1g2000yqn.googlegroups.com>
In reply to#9722
On Sep 4, 7:34 am, Paavo Helde <myfirstn...@osa.pri.ee> wrote:
> James Kanze <james.ka...@gmail.com> wrote
> innews:ca8f2f18-4f33-464e-9ec6-5519d4914d70@dl2g2000vbb.googlegroups.com:

    [...]
> >> Writing fast code in C is in principle easier as there are fewer high
> >> level constructs which could potentially cause slowdowns.

> > Writing fast code in C is significantly harder, because of the
> > lack of encapsulation.

> Only if one tries to emulate encapsulation by using means of non-zero
> runtime cost, like dynamically allocated data structures accessed via
> opaque pointers. If one does not attempt to have any encapsulation, then
> there is nothing which would get in the way of having fast code. Of
> course, ensuring that this fast code is also *correct* and *robust* and
> *maintainable* is significantly harder in C, unless the project is really
> small.

The fact that the maintainability is significantly harder means
that modifying the code to improve its performance is
significantly harder.  That's precisely my point.

--
James Kanze

[toc] | [prev] | [next] | [standalone]


#9647

FromGoran <goran.pusic@gmail.com>
Date2011-09-01 23:23 -0700
Message-ID<5b0359a6-d176-422b-9ce6-25217536e614@n12g2000yqh.googlegroups.com>
In reply to#9640
On Sep 2, 4:09 am, KaiWen <wenkai1...@gmail.com> wrote:
> On 9月2日, 上午6时34分, Joshua Maurice <joshuamaur...@gmail.com> wrote:
>
>
>
>
>
>
>
>
>
> > On Sep 1, 2:48 am, "Fred Zwarts \(KVI\)" <F.Zwa...@KVI.nl> wrote:
>
> > > "KaiWen"  wrote in message
>
> > >news:c5892d85-95b2-4e19-a11c-cde621a9ab4c@r40g2000prf.googlegroups.com...
>
> > > > Generally, are the programs written by C++ slower than written by C 10% ?
>
> > > It is not clear to me what you mean.
> > > C++ is more complicated than C, so C++ programs are written somewhat slower
> > > that C programs, because more thinking is needed. But, at the other hand,
> > > C++ usually needs less source code to complete a complex program (because of
> > > the availability of a rich library and the reuse of code in templates), so
> > > writing a program may be completed faster in C++ that in C.
>
> > Do you have any reliable evidence to make such a claim? I believe this
> > is a complete pull out of thin air without any supporting evidence.
> > I'll add my own pull out of thin air and claim that this is a non-
> > obvious claim.
>
> > I'll go even further actually. As long as the C++ constructs can map
> > nicely to "equivalent" C constructs, I see no reason why C++ programs
> > will be slower with a good compiler. It depends heavily on the exact
> > programs. Usually people make unfair apples-to-oranges comparisons of
> > an OO approach vs a procedural approach. When doing legitimate
> > comparisons, you will find the C and C++ program are much closer than
> > you think.
>
> We don't discuss OO here, just discuss the cost of compile time and
> the speed of program.
> 1. Compile a C++ program is slower than written by C
> 2. In runtime, the speed of the program written by C++ is <= the same
>    program written by C

For all practical intents and purposes, C++ is a subset of C.
Therefore, both these claims are theoretically false. ;-)

+1 for those who said that speed (and compile time, really) will
depend much, much more on your team's skills with C or C++ than on
some "inherent" difference between the two.

In other words, you're going about it in a wrong way.

> I want to write a program about network, parse huge number of data,
> so, with all due respect, I can not decide witch language to use.

Even worse. If that is so, then know this: network is orders of
magnitude "slower" than either C or C++. The time needed to establish
connections and transfer data between peers will easily swamp time
spent in your code.

>
> I know I can develop faster by using C++, but the speed of program
> in runtime is important too. So witch one is important? Can anyone
> give a suggestion?

Best suggestion I can give from what you have said so far is: speed-
wise, it is, by and large, IRRELEVANT whether you pick C or C++ (And,
you may just as well go for, I dunno, Java and still not have a
relevant difference in speed.)

Goran.

[toc] | [prev] | [next] | [standalone]


#9651

FromNick Keighley <nick_keighley_nospam@hotmail.com>
Date2011-09-02 03:00 -0700
Message-ID<333ee908-1ac5-4925-b2d2-379a168f00ec@a27g2000yqc.googlegroups.com>
In reply to#9647
On Sep 2, 7:23 am, Goran <goran.pu...@gmail.com> wrote:
> On Sep 2, 4:09 am, KaiWen <wenkai1...@gmail.com> wrote:
> > On 9月2日, 上午6时34分, Joshua Maurice <joshuamaur...@gmail.com> wrote:
> > > On Sep 1, 2:48 am, "Fred Zwarts \(KVI\)" <F.Zwa...@KVI.nl> wrote:
> > > > "KaiWen"  wrote in message
> > > >news:c5892d85-95b2-4e19-a11c-cde621a9ab4c@r40g2000prf.googlegroups.com...

> > > > > Generally, are the programs written by C++ slower than written by C 10% ?
>
> > > > It is not clear to me what you mean.
> > > > C++ is more complicated than C, so C++ programs are written somewhat slower
> > > > that C programs, because more thinking is needed. But, at the other hand,
> > > > C++ usually needs less source code to complete a complex program (because of
> > > > the availability of a rich library and the reuse of code in templates), so
> > > > writing a program may be completed faster in C++ that in C.
>
> > > Do you have any reliable evidence to make such a claim? I believe this
> > > is a complete pull out of thin air without any supporting evidence.
> > > I'll add my own pull out of thin air and claim that this is a non-
> > > obvious claim.
>
> > > I'll go even further actually. As long as the C++ constructs can map
> > > nicely to "equivalent" C constructs, I see no reason why C++ programs
> > > will be slower with a good compiler. It depends heavily on the exact
> > > programs. Usually people make unfair apples-to-oranges comparisons of
> > > an OO approach vs a procedural approach. When doing legitimate
> > > comparisons, you will find the C and C++ program are much closer than
> > > you think.
>
> > We don't discuss OO here, just discuss the cost of compile time and
> > the speed of program.
> > 1. Compile a C++ program is slower than written by C
> > 2. In runtime, the speed of the program written by C++ is <= the same
> >    program written by C
>
> For all practical intents and purposes, C++ is a subset of C.

seriously?

> Therefore, both these claims are theoretically false. ;-)

even if C were a subset of C++ I don't see how the statment is
theoretically untrue

> +1 for those who said that speed (and compile time, really) will
> depend much, much more on your team's skills with C or C++ than on
> some "inherent" difference between the two.
>
> In other words, you're going about it in a wrong way.
>
> > I want to write a program about network, parse huge number of data,
> > so, with all due respect, I can not decide witch language to use.
>
> Even worse. If that is so, then know this: network is orders of
> magnitude "slower" than either C or C++. The time needed to establish
> connections and transfer data between peers will easily swamp time
> spent in your code.
>
>
>
> > I know I can develop faster by using C++, but the speed of program
> > in runtime is important too. So witch one is important? Can anyone
> > give a suggestion?
>
> Best suggestion I can give from what you have said so far is: speed-
> wise, it is, by and large, IRRELEVANT whether you pick C or C++ (And,
> you may just as well go for, I dunno, Java and still not have a
> relevant difference in speed.)
>
> Goran.- Hide quoted text -
>
> - Show quoted text -

[toc] | [prev] | [next] | [standalone]


#9673

FromGoran <goran.pusic@gmail.com>
Date2011-09-02 09:39 -0700
Message-ID<f2a298bb-6cb9-4e04-bd4f-d79270eac5ce@c29g2000yqd.googlegroups.com>
In reply to#9651
On Sep 2, 12:00 pm, Nick Keighley <nick_keighley_nos...@hotmail.com>
wrote:
> On Sep 2, 7:23 am, Goran <goran.pu...@gmail.com> wrote:
>
>
>
>
>
>
>
>
>
> > On Sep 2, 4:09 am, KaiWen <wenkai1...@gmail.com> wrote:
> > > On 9月2日, 上午6时34分, Joshua Maurice <joshuamaur...@gmail.com> wrote:
> > > > On Sep 1, 2:48 am, "Fred Zwarts \(KVI\)" <F.Zwa...@KVI.nl> wrote:
> > > > > "KaiWen"  wrote in message
> > > > >news:c5892d85-95b2-4e19-a11c-cde621a9ab4c@r40g2000prf.googlegroups.com...
> > > > > > Generally, are the programs written by C++ slower than written by C 10% ?
>
> > > > > It is not clear to me what you mean.
> > > > > C++ is more complicated than C, so C++ programs are written somewhat slower
> > > > > that C programs, because more thinking is needed. But, at the other hand,
> > > > > C++ usually needs less source code to complete a complex program (because of
> > > > > the availability of a rich library and the reuse of code in templates), so
> > > > > writing a program may be completed faster in C++ that in C.
>
> > > > Do you have any reliable evidence to make such a claim? I believe this
> > > > is a complete pull out of thin air without any supporting evidence.
> > > > I'll add my own pull out of thin air and claim that this is a non-
> > > > obvious claim.
>
> > > > I'll go even further actually. As long as the C++ constructs can map
> > > > nicely to "equivalent" C constructs, I see no reason why C++ programs
> > > > will be slower with a good compiler. It depends heavily on the exact
> > > > programs. Usually people make unfair apples-to-oranges comparisons of
> > > > an OO approach vs a procedural approach. When doing legitimate
> > > > comparisons, you will find the C and C++ program are much closer than
> > > > you think.
>
> > > We don't discuss OO here, just discuss the cost of compile time and
> > > the speed of program.
> > > 1. Compile a C++ program is slower than written by C
> > > 2. In runtime, the speed of the program written by C++ is <= the same
> > >    program written by C
>
> > For all practical intents and purposes, C++ is a subset of C.
>
> seriously?
>
> > Therefore, both these claims are theoretically false. ;-)
>
> even if C were a subset of C++ I don't see how the statment is
> theoretically untrue

Whoops, lapsus linguae there... (blushes). I meant superset, of
course.

Goran.

[toc] | [prev] | [next] | [standalone]


#9662

FromRui Maciel <rui.maciel@gmail.com>
Date2011-09-02 12:44 +0100
Message-ID<4e60c1af$0$5999$a729d347@news.telepac.pt>
In reply to#9647
Goran wrote:

> For all practical intents and purposes, C++ is a subset of C.

I don't believe that features such as support for object-oriented 
programming, polymorphism, templates and namespaces can be excluded from 
"practical intents".


Rui Maciel

[toc] | [prev] | [next] | [standalone]


#9650

FromRui Maciel <rui.maciel@gmail.com>
Date2011-09-02 09:59 +0100
Message-ID<4e609add$0$6000$a729d347@news.telepac.pt>
In reply to#9640
KaiWen wrote:

> We don't discuss OO here, just discuss the cost of compile time and
> the speed of program.
> 1. Compile a C++ program is slower than written by C

How is this relevant?


> 2. In runtime, the speed of the program written by C++ is <= the same
>    program written by C

This, as I already pointed out, is false.


> I want to write a program about network, parse huge number of data,
> so, with all due respect, I can not decide witch language to use.

Possibly you are better served by using the language you are most proficient 
with.  Compilation time is practically irrelevant and speed efficiency 
doesn't depend on which of these two languages you use, only on what code 
you write.


Rui Maciel

[toc] | [prev] | [next] | [standalone]


#9677

FromBGB <cr88192@hotmail.com>
Date2011-09-02 11:25 -0700
Message-ID<j3r72u$24b$1@news.albasani.net>
In reply to#9650
On 9/2/2011 1:59 AM, Rui Maciel wrote:
> KaiWen wrote:
>
>> We don't discuss OO here, just discuss the cost of compile time and
>> the speed of program.
>> 1. Compile a C++ program is slower than written by C
>
> How is this relevant?
>

depends on the tasks.

although not as likely to be an issue for statically compiled C vs C++ 
(except maybe for someone worried about build times, or people getting 
bored and having a coffee break because building takes so long, ...) it 
may not matter much.

in terms of, say, writing a compiler for a script language which is 
often loaded-from-source (slower compile times thus meaning the app 
takes longer to start up, ...), then having a fast compiler matters a 
lot more.


>
>> 2. In runtime, the speed of the program written by C++ is<= the same
>>     program written by C
>
> This, as I already pointed out, is false.
>

actually, I think it can go either way (depending on programming styles 
in each case, ...).

however, if in both cases it is the same code (common subset of C and 
C++), with no "evil tricks" in the background (overloaded operators, 
...), one wouldn't expect to find much real difference.


>
>> I want to write a program about network, parse huge number of data,
>> so, with all due respect, I can not decide witch language to use.
>
> Possibly you are better served by using the language you are most proficient
> with.  Compilation time is practically irrelevant and speed efficiency
> doesn't depend on which of these two languages you use, only on what code
> you write.
>

yep.

[toc] | [prev] | [next] | [standalone]


#9683

FromJuha Nieminen <nospam@thanks.invalid>
Date2011-09-03 05:51 +0000
Message-ID<4e61c07d$0$3061$7b1e8fa0@news.nbl.fi>
In reply to#9640
KaiWen <wenkai1987@gmail.com> wrote:
> 2. In runtime, the speed of the program written by C++ is <= the same
>   program written by C

  Actually many equivalent constructs in C and C++ are such that it's
the exact opposite: C++ is significantly faster than C.

  Just two simple examples are qsort() vs. std::sort() , and strlen()
vs std::string::length(). Especially in the first case it's precisely
the language features that help the compiler make a faster executable.

[toc] | [prev] | [next] | [standalone]


#9687

FromBGB <cr88192@hotmail.com>
Date2011-09-03 01:45 -0700
Message-ID<j3speo$h90$1@news.albasani.net>
In reply to#9683
On 9/2/2011 10:51 PM, Juha Nieminen wrote:
> KaiWen<wenkai1987@gmail.com>  wrote:
>> 2. In runtime, the speed of the program written by C++ is<= the same
>>    program written by C
>
>    Actually many equivalent constructs in C and C++ are such that it's
> the exact opposite: C++ is significantly faster than C.
>
>    Just two simple examples are qsort() vs. std::sort() , and strlen()
> vs std::string::length(). Especially in the first case it's precisely
> the language features that help the compiler make a faster executable.

this again, comes down to coding practices...


also, just how many people really use "qsort()" anyways?...
IME, it is more often one of those largely forgotten functions (it is 
there, but more often people write out their own sort logic manually).

(actually, it seems to be fairly common practice in C land for people to 
largely ignore much of the standard library, and to write their own 
logic for doing things).


it is also not clear that std::string would be, in general, faster, and 
having an O(1) ability to fetch the length may turn out to be moot if 
most other operations tend towards being more expensive. not that 
worrying about micro-optimizing string operations is usually all that 
relevant though anyways.


from what I can gather from checking online (via Google), it seems where 
people have tried testing, the performance differences have tended to be 
negligible.

some other tests have apparently shown std::string operations to be 
about 4x slower than C-style strings.

[toc] | [prev] | [next] | [standalone]


Page 1 of 6  [1] 2 3 4 5 6  Next page →

Back to top | Article view | comp.lang.c++


csiph-web