Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #9766
| From | BGB <cr88192@hotmail.com> |
|---|---|
| Newsgroups | comp.lang.c++ |
| Subject | Re: Generally, are the programs written by C++ slower than written by C 10% ? |
| Date | 2011-09-05 14:06 -0700 |
| Organization | albasani.net |
| Message-ID | <j43dk2$5ap$1@news.albasani.net> (permalink) |
| References | (4 earlier) <4e61c07d$0$3061$7b1e8fa0@news.nbl.fi> <j3speo$h90$1@news.albasani.net> <875f9e1f-79f1-49fa-8667-f440e8cc4c69@fd21g2000vbb.googlegroups.com> <j43884$faj$1@news.albasani.net> <9cknhoF72aU1@mid.individual.net> |
On 9/5/2011 12:51 PM, Ian Collins wrote:
> On 09/ 6/11 07:34 AM, BGB wrote:
>> On 9/5/2011 12:28 AM, Nick Keighley wrote:
>>> On Sep 3, 9:45 am, BGB<cr88...@hotmail.com> wrote:
>>>
>>> If I'm coding in C and I want to sort something. My first thought
>>> would be qsort()! If it was too slow only then would I consider hand
>>> coding it. Surely any constructively lazy person would use an existing
>>> facility rather hand-roll their own!
>>>
>>
>> different styles for different sorts...
>>
>>
>> actually, in my case I would probably far more likely copy-paste it and
>> then edit it to the new use.
>>
>> copy-paste is a powerful tool which is often disparaged and overlooked.
>
> Rightly so. C has things call functions that enable code to be reused
> and C++ has function templates that remove the last excuse for copy and
> paste.
>
>> but, one would typically write it themselves initially (before
>> subjecting it to endless copy-paste).
>
> Not if they were being paid to deliver software.
>
well, if they just copy/paste it from existing sources, they may be
stuck with GPL nastiness or similar (since, annoyingly, the majority of
existing/FOSS source is GPL), so writing it initially will give them a
version for which they control the license (while still being legal, and
not simply "forgetting" the per-existing license terms).
for example, I have ended up having to write pretty much a whole damn 3D
engine to get away from the GPL and stay reasonably close to familiar
territory (my plans are to use the MIT license for most of the core).
recently I have (at least experimentally) loaded up Doom3 maps in my own
engine, however for the most part I have previously been using
Quake-style maps (mostly from Quake 1). I had also loaded up maps from
Xonotic (sort of like a Quake-3 Arena clone based on a heavily modified
Quake-1 engine, namely DarkPlaces).
>>>> 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.
>>>
>>> are they?
>>>
>>
>> from what I have seen, people tend to pass them around by-value.
>
> Most C++ code passes strings by const reference.
>
I guess people do both.
I had seen references to it apparently being a style debate between
using references and passing them by value, with different performance
tradeoffs existing between compilers.
>> apparently, the by-value vs by-reference thing makes a bit of a
>> difference WRT performance.
>>
>> apparently, their performance characteristics also differ some between
>> GCC and MSVC, with the ones in MSVC apparently tending to be more
>> expensive.
>>
>> granted, I haven't personally looked into all of this in-depth though.
>
> With some compilers in some modes, passing a string by value will be
> quicker if the string object (typically a pair of pointers) is small
> enough to pass in registers.
>
dunno, it depends on the compiler.
the version of the object I am familiar with happens to contain (IIRC) a
reference count, a maximum size (capacity), a length field, and a
character array aliased against a pointer.
>> there are also plenty of things often done with C strings as well that
>> can make them faster, such as interning them so that one can check
>> string equality using '==' on the pointers, rather than using
>> "!strcmp()", ...
>
> In other words, wrapping them like std::string...
>
yep, except that this also works with plain C (relevant since the
project is largely mixed-language, and C-style is the only thing
"everyone" understands).
actually, it is more restricted than this, typically not only do they
have to be plain C types but also visible to the garbage collector and
to the VM type-system.
technically, the pointer values are equivalent, but different functions
are used to return either "char *" or "dyt" (a magic type used for
dynamically typed objects), mostly to avoid the need for manual casting
or the compiler throwing a fit due to implicit pointer-type conversions.
trivia:
there are overloaded operators so that "dyt" behaves more like a
built-in type in C++, whereas one needs things like "dyadd(a, b)" in C.
for many shared-language constructs, it is usually least effort to make
them behave C-like internally, and give optional overloaded operators or
wrapper classes for the C++ case.
in a few cases, the methods actually just redirect, either to calling
through a function-pointer (for C and C++ code to implement the real
logic), or redirecting the call into the scripting VM (such as if a
VM-managed object is placed into a field, such as "dy_this").
say, for example:
void FooObject::fooMethod()
{
if(dy_this)
{
dyCallSigv(dy_this, "fooMethod", "()v");
return;
}
if(vtable->fooMethof_f)
vtable->fooMethof_f();
}
it can all get kind of hairy at times, but it works...
>> in my case, I tend to avoid "stdrup()" as well, as generally "strdup()"
>> is a good way to "make bad things happen" (slow, tears through huge
>> amounts of memory, leaves the program responsible to free them, ...), so
>> preferable IMO is interning them into string-tables (a big glob of
>> memory where they are packed end-to-end).
>>
>> then one can free the whole string table as part of a "teardown" process.
>>
>> another strategy (used elsewhere) is to allocate the strings in the
>> garbage-collected heap (I use GC), and then manage them using a weak
>> hash (entries will be reset to NULL whenever any are reclaimed by the
>> GC).
>>
>>
>> also, == and != work provided both strings are in the same string-table.
>
> Or save a whole lot of pain and use std::string.
>
except, as noted above, I can't do this generally, as C++ is only used
in parts of the project.
granted, std::string makes a lot more sense for a pure-C++ project (or
at least a "strongly dominantly C++" project).
Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
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
csiph-web