Talk About Network

Google





Programming > C - C++ Learning > Lesson 6: Strin...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 4 Topic 4113 of 4400
Post > Topic >>

Lesson 6: Strings. (Performance Killer?!?)

by "TheDevil" <TheDevil@[EMAIL PROTECTED] > Apr 15, 2008 at 12:12 AM

Hello,

See assembly in IDE (not provided in message, would be too long)

See comments or see website:

http://members.home.nl/hbthouppermans/VS2008Analysis/Index.htm

// *** Begin of Main.cpp ***

/*

14 april 2008

Lesson 6, Strings

The C++ Standard Template Library (STL) contains a string class.

In order to use the string class you should include the following 
statements:

#include <string>
using std::string;

Conclusion:

Incompatible with printf, must use special function.
Total performance killer, programmer didn't know what he was doing.
No further testing will be done since this is a showstopper.
Debugger hang while debugging.
IDE hang after terminating debugger service, and trying to re-debug.
Breakpoints lost after project re-opened via recent projects.

Score:

0 out of 10.

*/

#include <string>
using std::string;

int main()
{
    printf("Program Started \n");

    string S = "Hello World !"; // 13 characters + 1 for null character, 
HUNDREDS OF INSTRUCTIONS NEEDED. NOT GOOD.

    // TEST 1
//    cout << S;  // compile error: 'cout': undeclared identifier, BAD.

    // TEST 2
//    printf("%s \n", S );    // result: <NULL>, BAD.

    // TEST 3
//    printf("%s \n", &S );   // result: , BAD.

    // TEST 4
//    printf("%s \n", S.c_str ); // compile error: function call missing, 
BAD.

    // TEST 5
//    printf("%s \n", S.c_str() ); // result: Hello World, OK.

    // TEST 6
//    printf("string.length: %d \n", S.length ); // compile error:
function 
call missing, BAD.

    // TEST 7
    printf("string.length: %d \n", S.length() ); // result: 13, OK. 
Algorithm: FAST/OPTIMAL. Length-Prefixed.

    // TEST 8
    S = S + " How are you today ?"; // Result: 20 additional characters,
for 
a total of 33, OK
                                    // Algorithm: TOTAL PERFORMANCE
FAILURE. 
Hundreds of instructions needed. For debug and release mode.
                                    // Probable cause: Programmer used 
templates and had no idea what the resulting performance would be.
                                    // Short conclusion: Programmer didn't

know what he was doing at the instruction/performance level.

    // TEST 9
    printf("string.length: %d \n", S.length() ); // result: 33, OK.

    // alternative:
    char *vString1;
    char *vString2;
    char *vString3;

    int vIndex;

    vString1 = new char[14]; // total algorithm failure, requires many, 
many, many instructions
    vString2 = new char[21];
    vString3 = new char[34];

    vString1 = "Hello World !";
    vString2 = " How are you today ?";

    // few hundred instructions or so.
    for (vIndex=0; vIndex<=12; vIndex++)
    {
        vString3[vIndex] = vString1[vIndex];
    }

    for (vIndex=0; vIndex<=20; vIndex++)
    {
        vString3[13+vIndex] = vString2[vIndex];
    }
    vString3[33] = 0;

    printf("Test: %s \n", vString3 );

    printf("Program finished \n");
}

// *** End of Main.cpp ***

Bye,
  The Devil.
 




 4 Posts in Topic:
Lesson 6: Strings. (Performance Killer?!?)
"TheDevil" <  2008-04-15 00:12:11 
Re: Lesson 6: Strings. (Performance Killer?!?)
LR <lruss@[EMAIL PROTE  2008-04-14 18:22:42 
Re: Lesson 6: Strings. (Performance Killer?!?)
utab <umut.tabak@[EMAI  2008-04-14 16:26:25 
Re: Lesson 6: Strings. (Performance Killer?!?)
Richard Heathfield <rj  2008-04-15 05:35:06 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
localhost-V2008-12-19 Wed Jan 7 10:55:34 PST 2009.