K
KaiWen
Generally, are the programs written by C++ slower than written by C
10% ?
10% ?
Generally, are the programs written by C++ slower than written by C
10% ?
Generally, are the programs written by C++ slower than written by C 10% ?
KaiWen said:Generally, are the programs written by C++ slower than written by C
10% ?
"KaiWen" wrote in message
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.
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?
but the speed of program in runtime is important too.
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?
KaiWen said: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.
For all practical intents and purposes, C++ is a subset of C.
seriously?
Therefore, both these claims are theoretically false. ;-)
Goran said:For all practical intents and purposes, C++ is a subset of C.
even if C were a subset of C++ I don't see how the statment is
theoretically untrue
How is this relevant?
This, as I already pointed out, is false.
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.
KaiWen said:2. In runtime, the speed of the program written by C++ is <= the same
program written by C
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?
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).
BGB said: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.
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.