C++ slowness

This is a discussion on C++ slowness within the C++ Programming forums, part of the General Programming Boards category; Polymorphic OOP "Matrix operations? What "operations" are you talking about?" Well with my limited knowledge about C++ ,i give u ...

  1. #16
    Registered User SAMSAM's Avatar
    Join Date
    Nov 2001
    Posts
    218
    Polymorphic OOP

    "Matrix operations? What "operations" are you talking about?"

    Well with my limited knowledge about C++ ,i give u this example:
    C++ matrix algebra, via matrix object.
    i can point out that in matrix
    manupulation or multip(inversion, triangular) and in complex computing

    dont you think by representing every number as an
    object ,and instatiating it you are creating a unneeded
    additional overhead?

    each number requires more mem as an object. doesnt it?
    wouldnt each calling of an object create additional
    overhead.

    My haunch may be unfounded. but i would think if i
    use OO method for these operation , it would be slower
    than its procedural version.


    cheers!

    *note
    I have never done any test on any of these topics.
    so i am only assuming the results would be what i
    think it would.

    edit:
    iam very new to the usage of matrix manup in C++.
    and currently reading on it on the side as iam reading
    a C++ book by deitel&deitel.
    Last edited by SAMSAM; 04-12-2003 at 10:25 AM.

  2. #17
    Xei
    Xei is offline
    Registered User Xei's Avatar
    Join Date
    May 2002
    Posts
    719
    You know, even though many people may disagree, C/C++ are still high level languages. Since I have registered to the CBoard I've seen numerous arguements about the speed differences of C and C++. I think that we should put them both to the test, with lets say... 200-500 million iterations of some kind? with different kinds of situations. So we could compare exact code, then OOP C++ with C, etc. Then when compiling we would have to make sure that all of the same compile options are selected, etc. There might be some websites with 'statistics' of some kind, but if we do it ourselves then we will all know the kind of sacrifices we give up when using C++ rather than C, and C rather than C++. Does this sound like a good idea?
    Last edited by Xei; 04-12-2003 at 01:24 PM.

  3. #18
    Banned
    Join Date
    Jan 2003
    Posts
    1,708
    Yes, but I'm satisified that C++ comes with some overhead which becomes a moot point due to the fact that
    1) it isn't all that much overhead to begin with
    2) compilers come optimized and come with more options that optimize speed further
    3) processors today have speed to burn

    an example I was told that comes with some overhead was with inheritance and virtual methods, that the compiler has to check the v table to make sure the correct functions get called and stuff like that, but it really isn't a big deal.

  4. #19
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    Originally posted by SAMSAM
    dont you think by representing every number as an
    object ,and instatiating it you are creating a unneeded
    additional overhead?

    each number requires more mem as an object. doesnt it?
    wouldnt each calling of an object create additional
    overhead.
    If you want to call a built-in datatype of C++, that's up to you, but for intents and purposes, they're the same in C and in C++. Objects do not ever require extra space unless they use virtual functions. Nonvirtual function calls are done just like in C. There is no overhead in creating and using built-in datatypes (or even userdefined types with nonvirtual member functions).

    an example I was told that comes with some overhead was with inheritance and virtual methods, that the compiler has to check the v table to make sure the correct functions get called and stuff like that, but it really isn't a big deal.
    That's because you literally can't do that in C without manually making a vtable (or some other way of forcing the proper function call). This is one of the features I was talking about where it makes no sense to compare to C because there is no equivalent to it in C. What it comes down to is if you wanted to simulate virtual functions in C, you'd have to manually create and manage your own vtables and do explicit pointer casting, and still not get the benefit of an explicit hierarchy and simple syntax. Your code would not most-likely not be any faster, either. Just a hell-of-a-lot less readable.

    You know, even though many people may disagree, C/C++ are still high level languages. Since I have registered to the CBoard I've seen numerous arguements about the speed differences of C and C++. I think that we should put them both to the test, with lets say... 200-500 million iterations of some kind? with different kinds of situations. So we could compare exact code, then OOP C++ with C, etc. Then when compiling we would have to make sure that all of the same compile options are selected, etc. There might be some websites with 'statistics' of some kind, but if we do it ourselves then we will all know the kind of sacrifices we give up when using C++ rather than C, and C rather than C++. Does this sound like a good idea?
    No, simply because of compiler differences, etc. as well as the fact that you explicitly said OO C++. Why not just use the procedural portion of C++ if you wanted an accurate comparison. You could usually even use exactly the same syntax. If you don't use the procedural portion of C++ then you're just going to be comparing two completely different things so a test would prove nothing. Either way, you're not going to get truely accurate results, and besides, once again, the languages themselves are not "slower or faster" so any tests you do only represent the compiler you're using and your system, not the language.
    Last edited by Polymorphic OOP; 04-12-2003 at 05:20 PM.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21