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.


|