Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Generally, are the programs written by C++ slower than written by C10% ?

Reply
Thread Tools

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

 
 
KaiWen
Guest
Posts: n/a
 
      09-01-2011
Generally, are the programs written by C++ slower than written by C
10% ?
 
Reply With Quote
 
 
 
 
Ian Collins
Guest
Posts: n/a
 
      09-01-2011
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
 
Reply With Quote
 
 
 
 
Fred Zwarts \(KVI\)
Guest
Posts: n/a
 
      09-01-2011
"KaiWen" wrote in message
news:(E-Mail Removed)...

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

 
Reply With Quote
 
A
Guest
Posts: n/a
 
      09-01-2011
It is not actually the language that might be slower because you can do
equal things in C and C++ that execute approximately the same speed, what
matters might be overhead that some C++ constructs imply on the program. But
that is only if you use such constructs... such as templates for example.
Even templates can also be used in a right and wrong way. So the answer is
far from being general. In good hands each tool can work wonders or be just
as average as any other tool.

For example:

std::vector<int> abc;
abc.at(0) = 1; // is slower than
abc[0] = 1; // than this because of range checking

In C you don't even have such constructs so there is nothing to compare it
to. But if you use at() which does some additional overhead due to range
checking then of course it is somewhat slower than the other version. It is
like you would call more functions in C, that would execute slower due to
heap/stack allocation etc.

But in C++ you could as well write:

char[] abc = "abc";
abc[0] = "x";

that would work equally fast in C or C++.

In general, there is only one REAL issue - which of the two you find more
valuable - the convenience that C++ offers over C to speedup development...
or... your time.... to finish a certain project (even if it is a bit
slower). Remember, programmers time is never getting more expensive it may
only get cheaper.


 
Reply With Quote
 
Rui Maciel
Guest
Posts: n/a
 
      09-01-2011
KaiWen wrote:

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


Why would they be?

Just for the sake of argument, here are some benchmarks comparing the
results of a C implementation to those of a C++ implementation.

http://shootout.alioth.debian.org/u64q/cpp.php
http://shootout.alioth.debian.org/u6...languages-are-
fastest.php?gpp=on&gcc=on&calc=chart


Rui Maciel
 
Reply With Quote
 
Joshua Maurice
Guest
Posts: n/a
 
      09-01-2011
On Sep 1, 2:48*am, "Fred Zwarts \(KVI\)" <(E-Mail Removed)> wrote:
> "KaiWen" *wrote in message
>
> news:(E-Mail Removed)...
>
> > 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 (becauseof
> 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.
 
Reply With Quote
 
KaiWen
Guest
Posts: n/a
 
      09-02-2011
On 9月2日, 上午6时34分, Joshua Maurice <(E-Mail Removed)> wrote:
> On Sep 1, 2:48 am, "Fred Zwarts \(KVI\)" <(E-Mail Removed)> wrote:
>
> > "KaiWen" wrote in message

>
> >news:(E-Mail Removed)....

>
> > > 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?
 
Reply With Quote
 
Ian Collins
Guest
Posts: n/a
 
      09-02-2011
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
 
Reply With Quote
 
Krice
Guest
Posts: n/a
 
      09-02-2011
On 2 syys, 05:09, KaiWen <(E-Mail Removed)> 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++.
 
Reply With Quote
 
Goran
Guest
Posts: n/a
 
      09-02-2011
On Sep 2, 4:09 am, KaiWen <(E-Mail Removed)> wrote:
> On 9月2日, 上午6时34分, Joshua Maurice <(E-Mail Removed)> wrote:
>
>
>
>
>
>
>
>
>
> > On Sep 1, 2:48 am, "Fred Zwarts \(KVI\)" <(E-Mail Removed)> wrote:

>
> > > "KaiWen" wrote in message

>
> > >news:(E-Mail Removed)....

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

>
> > > 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: HELP! Ping getting slower and slower and slower! Paul Computer Information 2 04-03-2012 05:58 PM
XPath queries getting slower and slower... Andre Charbonneau Java 0 02-15-2005 05:04 PM
Google groups (Beta version) is much slower than original usenet69@hotmail.com Firefox 4 02-09-2005 04:21 PM
Anyone else notice that FirFox 1.0 is slower than .8 and .9? Jeff Ingram Firefox 18 12-01-2004 01:48 PM
Dialup modem connects at slower and slower speeds Sharon Sharp Computer Support 7 10-13-2004 02:51 PM



Advertisments