As I've just
posted over at my blog I'm sitting the 70-536 .Net Framework 2.0 Application Development Foundation exam tomorrow (more for my employer's benefit than my own), but I'm seriously frustrated with the quality of the training materials.
Have any niners sat this test, and is it any better in 'real life' than the appalling practice test supplied with the official training kit?
-
-
Actually it's one and four! Both are the fastest. The StringBuilder is only faster if you have more then 7-9 concats!
-
<snipped />
-
littleguru wrote:Actually it's one and four! Both are the fastest. The StringBuilder is only faster if you have more then 7-9 concats!
Damn, I hate it when people modify their posts - it makes any replies nonsensical [6]
Anyway, yes both 1 and 4 are the most efficient which is the point of my post - yet the test exam will mark you as being wrong. The answer it wants is for option 3. -
<snipped too />
-
Actually this would be the fastest one.
string s1 = "Hello";
string s2 = ", ";
string s3 = "World";
string s4 = "!";
string s = string.Concat(s1, s2, s3, s4);
But it's not an option
-
After trying it in a little console application this are the results with 10,000,000 iterations.
string.Concat: 00:00:01.7713710
StringBuilder: 00:00:03.2878755
DateTime start = DateTime.Now;
for (int i = 0; i < 10000; i++)
{
string s1 = "Hello";
string s2 = ", ";
string s3 = "World";
string s4 = "!";
string s = string.Concat(s1, s2, s3, s4);
}
DateTime end = DateTime.Now;
Console.WriteLine(end - start);
start = DateTime.Now;
for (int i = 0; i < 10000; i++)
{
string s = null;
StringBuilder sb = new StringBuilder();
sb.Append("Hello");
sb.Append(", ");
sb.Append("World");
sb.Append("!");
s = sb.ToString();
}
end = DateTime.Now;
Console.WriteLine(end - start);
Console.ReadLine(); -
IceFreak2000 wrote:As I've just posted over at my blog I'm sitting the 70-536 .Net Framework 2.0 Application Development Foundation exam tomorrow (more for my employer's benefit than my own), but I'm seriously frustrated with the quality of the training materials.
Have any niners sat this test, and is it any better in 'real life' than the appalling practice test supplied with the official training kit?
http://www.heikniemi.net/hc/archives/000124.html
Good luck with the exam. The questions are different from the ones in the Training Kit. I had some questions at the exam that had nthing to do with the material coverd by the Training Kit. Of course, if you have some experience with the .NET Framework, it's not going to be hard to get your certification.
Good luck!
-
naicul wrote:

IceFreak2000 wrote: As I've just posted over at my blog I'm sitting the 70-536 .Net Framework 2.0 Application Development Foundation exam tomorrow (more for my employer's benefit than my own), but I'm seriously frustrated with the quality of the training materials.
Have any niners sat this test, and is it any better in 'real life' than the appalling practice test supplied with the official training kit?
http://www.heikniemi.net/hc/archives/000124.html
Good luck with the exam. The questions are different from the ones in the Training Kit. I had some questions at the exam that had nthing to do with the material coverd by the Training Kit. Of course, if you have some experience with the .NET Framework, it's not going to be hard to get your certification.
Good luck!
Cheers naicul - as it happens I've just got back from the testing center after passing the exam by a very comfortable margin. Suffice it to say that the 'real' exam questions were not nearly as bad as the training materials had me expecting. -
littleguru wrote:After trying it in a little console application this are the results with 10,000,000 iterations.
string.Concat: 00:00:01.7713710
StringBuilder: 00:00:03.2878755
DateTime start = DateTime.Now;
for (int i = 0; i < 10000; i++)
{
string s1 = "Hello";
string s2 = ", ";
string s3 = "World";
string s4 = "!";
string s = string.Concat(s1, s2, s3, s4);
}
DateTime end = DateTime.Now;
Console.WriteLine(end - start);
start = DateTime.Now;
for (int i = 0; i < 10000; i++)
{
string s = null;
StringBuilder sb = new StringBuilder();
sb.Append("Hello");
sb.Append(", ");
sb.Append("World");
sb.Append("!");
s = sb.ToString();
}
end = DateTime.Now;
Console.WriteLine(end - start);
Console.ReadLine();
To make the test fair we should remove the bold line, declare s on the same line as its initialization, and then rerun it (or you could, instead, set s to null in the first loop also.)
string s = sb.ToString();
EDIT: StringBuilder beat out the Concat on my Vista RTM machine, but it's reversed on my XP box. -
I still do not see why splitting the two should have any significant difference on the output, since they're both operations that must be performed anyway.
My final results (each run 50 times, interleaved, for an average figure)
* original call using concat: 18.75 ms
* builder combined with declaration: 38.28125 ms
* builder, w/ string declared seperately: 42.96875 ms
This is what happens when coders debate optimization. -
IceFreak2000 wrote:

naicul wrote: 
IceFreak2000 wrote: As I've just posted over at my blog I'm sitting the 70-536 .Net Framework 2.0 Application Development Foundation exam tomorrow (more for my employer's benefit than my own), but I'm seriously frustrated with the quality of the training materials.
Have any niners sat this test, and is it any better in 'real life' than the appalling practice test supplied with the official training kit?
http://www.heikniemi.net/hc/archives/000124.html
Good luck with the exam. The questions are different from the ones in the Training Kit. I had some questions at the exam that had nthing to do with the material coverd by the Training Kit. Of course, if you have some experience with the .NET Framework, it's not going to be hard to get your certification.
Good luck!
Cheers naicul - as it happens I've just got back from the testing center after passing the exam by a very comfortable margin. Suffice it to say that the 'real' exam questions were not nearly as bad as the training materials had me expecting.
Congrats on passing the test. I'm working on upgrading my MCSA from Win2k to Win2k3 and also my SMS cert for work
After that I guess it will be time to get my LPI-C Level 1 to go along w/ my Linux+
I love that my company gives me a nice bonus for each test I pass
-
I'd recommend the microsoft book just from the nifty labs. Not sure how it compares to the test as I am currently studying for it.
-
DivideByZero wrote:I still do not see why splitting the two should have any significant difference on the output, since they're both operations that must be performed anyway.
My final results (each run 50 times, interleaved, for an average figure)
* original call using concat: 18.75 ms
* builder combined with declaration: 38.28125 ms
* builder, w/ string declared seperately: 42.96875 ms
This is what happens when coders debate optimization.
Well. Look at this:
string f = "foo" + "bar" + "foo" + "bar";
If this is concatted you get the following:
string f1 = string.Concat("foo", "bar");
string f2 = string.Concat(f1, "foo");
string f = string.Concat(f2, "bar");
You see that this creates three string instances instead of one final. The other instances "foo", "bar" are created in both approaches. You can't avoid that.
But you can avoid creating f1 and f2, by using the StringBuilder.
This is avery simple sample and could be optimized by the compiler, but there are complexer where with a concat different instances of string are created that aren't with StringBuilder. StringBuilder uses internal "magic" to avoid that.
Thread Closed
This thread is kinda stale and has been closed but if you'd like to continue the conversation, please create a new thread in our Forums,
or Contact Us and let us know.