473,320 Members | 1,867 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

String performance optimization

A year or two ago, I read an article on Microsoft's MSDN or Patterns and
Practices site about application optimization when using strings. Some of
the recommendations were:

use string.Empty rather than "",
use string.Compare rather than myString == myOtherString,
etc., etc.

I have been searching for days now for that article or those performance
guidelines and can't find it. Does anyone know where that article, or any
similar Microsoft article may be found?

Thanks,

Dale
--
Dale Preston
MCAD C#
MCSE, MCDBA
Nov 17 '05 #1
7 1375
Refer the following articl
http://msdn.microsoft.com/library/de...etperftips.asp
--
Regards,
Amal [MCP, MCS]
http://geocities.com/techsharing
"Dale" wrote:
A year or two ago, I read an article on Microsoft's MSDN or Patterns and
Practices site about application optimization when using strings. Some of
the recommendations were:

use string.Empty rather than "",
use string.Compare rather than myString == myOtherString,
etc., etc.

I have been searching for days now for that article or those performance
guidelines and can't find it. Does anyone know where that article, or any
similar Microsoft article may be found?

Thanks,

Dale
--
Dale Preston
MCAD C#
MCSE, MCDBA

Nov 17 '05 #2
That's a great article, but it doesn't address either of these specific
string performance issues.

I do appreciate your reply. If you, or anyone else, know of the article
that was devoted to string performance issues including the specific items I
listed, I would sure like to find it again.

Thanks again,

Dale
--
Dale Preston
MCAD C#
MCSE, MCDBA
"Amalorpavanathan Yagulasamy(AMAL)MCP,MCS" wrote:
Refer the following article
http://msdn.microsoft.com/library/de...etperftips.asp
--
Regards,
Amal [MCP, MCS]
http://geocities.com/techsharing
"Dale" wrote:
A year or two ago, I read an article on Microsoft's MSDN or Patterns and
Practices site about application optimization when using strings. Some of
the recommendations were:

use string.Empty rather than "",
use string.Compare rather than myString == myOtherString,
etc., etc.

I have been searching for days now for that article or those performance
guidelines and can't find it. Does anyone know where that article, or any
similar Microsoft article may be found?

Thanks,

Dale
--
Dale Preston
MCAD C#
MCSE, MCDBA

Nov 17 '05 #3
Refer this
http://msdn.microsoft.com/library/de...netchapt05.asp

and

http://msdn.microsoft.com/library/de...netchapt13.asp

--
Regards,
Amal [MCP, MCS]
http://geocities.com/techsharing
"Dale" wrote:
That's a great article, but it doesn't address either of these specific
string performance issues.

I do appreciate your reply. If you, or anyone else, know of the article
that was devoted to string performance issues including the specific items I
listed, I would sure like to find it again.

Thanks again,

Dale
--
Dale Preston
MCAD C#
MCSE, MCDBA
"Amalorpavanathan Yagulasamy(AMAL)MCP,MCS" wrote:
Refer the following article
http://msdn.microsoft.com/library/de...etperftips.asp
--
Regards,
Amal [MCP, MCS]
http://geocities.com/techsharing
"Dale" wrote:
A year or two ago, I read an article on Microsoft's MSDN or Patterns and
Practices site about application optimization when using strings. Some of
the recommendations were:

use string.Empty rather than "",
use string.Compare rather than myString == myOtherString,
etc., etc.

I have been searching for days now for that article or those performance
guidelines and can't find it. Does anyone know where that article, or any
similar Microsoft article may be found?

Thanks,

Dale
--
Dale Preston
MCAD C#
MCSE, MCDBA

Nov 17 '05 #4
Thank you again. More great articles and they're very helpful; I'd recommend
them to anyone.

The article I am looking for specifically addresses the issue of using
string.Empty instead of using "". The reason it gave, which makes sense to
me, is that string.Empty already exists while each time you use "" the
framework must allocate memory, create the necessary structure, and then
return the string.

Dale
--
Dale Preston
MCAD C#
MCSE, MCDBA
"Amalorpavanathan Yagulasamy(AMAL)MCP,MCS" wrote:
Refer this
http://msdn.microsoft.com/library/de...netchapt05.asp

and

http://msdn.microsoft.com/library/de...netchapt13.asp

--
Regards,
Amal [MCP, MCS]
http://geocities.com/techsharing
"Dale" wrote:
That's a great article, but it doesn't address either of these specific
string performance issues.

I do appreciate your reply. If you, or anyone else, know of the article
that was devoted to string performance issues including the specific items I
listed, I would sure like to find it again.

Thanks again,

Dale
--
Dale Preston
MCAD C#
MCSE, MCDBA
"Amalorpavanathan Yagulasamy(AMAL)MCP,MCS" wrote:
Refer the following article
http://msdn.microsoft.com/library/de...etperftips.asp
--
Regards,
Amal [MCP, MCS]
http://geocities.com/techsharing
"Dale" wrote:

> A year or two ago, I read an article on Microsoft's MSDN or Patterns and
> Practices site about application optimization when using strings. Some of
> the recommendations were:
>
> use string.Empty rather than "",
> use string.Compare rather than myString == myOtherString,
> etc., etc.
>
> I have been searching for days now for that article or those performance
> guidelines and can't find it. Does anyone know where that article, or any
> similar Microsoft article may be found?
>
> Thanks,
>
> Dale
> --
> Dale Preston
> MCAD C#
> MCSE, MCDBA

Nov 17 '05 #5
Dale <Da******@eMmeSseNn.com> wrote:
Thank you again. More great articles and they're very helpful; I'd recommend
them to anyone.

The article I am looking for specifically addresses the issue of using
string.Empty instead of using "". The reason it gave, which makes sense to
me, is that string.Empty already exists while each time you use "" the
framework must allocate memory, create the necessary structure, and then
return the string.


That's completely wrong, as literals are interned.

In fact, String.Empty and "" end up as the same references. Personally
I prefer "" from a readability point of view, and *all* of these
performance "tips" should be taken with a heavy dose of common sense -
chances are that your app's performance bottleneck *isn't* going to be
affected by almost any of them. The one exception is string
concatenation in a loop, where a StringBuilder should be used.
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #6
That's not true. The compiler (not even the JIT, if I recally correctly)
will optimize "".

At any rate, all string literals (strings with " and " around them) are
interned and so there is only ever ONE instance of them.

So even if "" weren't optimized by the compiler to be String.Empty, it would
be interned ONE time. You could have 15 million references
to "" in your code, but the compiler-or-JIT would convert them to a call to
retrieve the interned instance.

As far as String.Compare(), I'm not sure that it helps with simple x == y
comparions. Where it really helps is if you need to perform case-insensitive
and/or culture-insensitive comparisons.

-c

"Dale" <Da******@eMmeSseNn.com> wrote in message
news:6F**********************************@microsof t.com...
Thank you again. More great articles and they're very helpful; I'd
recommend
them to anyone.

The article I am looking for specifically addresses the issue of using
string.Empty instead of using "". The reason it gave, which makes sense
to
me, is that string.Empty already exists while each time you use "" the
framework must allocate memory, create the necessary structure, and then
return the string.

Dale
--
Dale Preston
MCAD C#
MCSE, MCDBA
"Amalorpavanathan Yagulasamy(AMAL)MCP,MCS" wrote:
Refer this
http://msdn.microsoft.com/library/de...netchapt05.asp

and

http://msdn.microsoft.com/library/de...netchapt13.asp

--
Regards,
Amal [MCP, MCS]
http://geocities.com/techsharing
"Dale" wrote:
> That's a great article, but it doesn't address either of these specific
> string performance issues.
>
> I do appreciate your reply. If you, or anyone else, know of the
> article
> that was devoted to string performance issues including the specific
> items I
> listed, I would sure like to find it again.
>
> Thanks again,
>
> Dale
> --
> Dale Preston
> MCAD C#
> MCSE, MCDBA
>
>
> "Amalorpavanathan Yagulasamy(AMAL)MCP,MCS" wrote:
>
> > Refer the following article
> > http://msdn.microsoft.com/library/de...etperftips.asp
> > --
> > Regards,
> > Amal [MCP, MCS]
> > http://geocities.com/techsharing
> >
> >
> > "Dale" wrote:
> >
> > > A year or two ago, I read an article on Microsoft's MSDN or
> > > Patterns and
> > > Practices site about application optimization when using strings.
> > > Some of
> > > the recommendations were:
> > >
> > > use string.Empty rather than "",
> > > use string.Compare rather than myString == myOtherString,
> > > etc., etc.
> > >
> > > I have been searching for days now for that article or those
> > > performance
> > > guidelines and can't find it. Does anyone know where that article,
> > > or any
> > > similar Microsoft article may be found?
> > >
> > > Thanks,
> > >
> > > Dale
> > > --
> > > Dale Preston
> > > MCAD C#
> > > MCSE, MCDBA

Nov 17 '05 #7
Thank you Jon and Chad. I appreciate the replies. That must be why the
specific article I remember can't be found anymore. It was probably removed
because it was in error.

Dale

--
Dale Preston
MCAD C#
MCSE, MCDBA
"Jon Skeet [C# MVP]" wrote:
Dale <Da******@eMmeSseNn.com> wrote:
Thank you again. More great articles and they're very helpful; I'd recommend
them to anyone.

The article I am looking for specifically addresses the issue of using
string.Empty instead of using "". The reason it gave, which makes sense to
me, is that string.Empty already exists while each time you use "" the
framework must allocate memory, create the necessary structure, and then
return the string.


That's completely wrong, as literals are interned.

In fact, String.Empty and "" end up as the same references. Personally
I prefer "" from a readability point of view, and *all* of these
performance "tips" should be taken with a heavy dose of common sense -
chances are that your app's performance bottleneck *isn't* going to be
affected by almost any of them. The one exception is string
concatenation in a loop, where a StringBuilder should be used.
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 17 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Thomas | last post by:
Does anyone know if the stl string class implements some sort of pooling or chunking of memory for performance optimization? I know that the Lucent SCL has this built in, but not sure if the same...
9
by: Rune | last post by:
Is it best to use double quotes and let PHP expand variables inside strings, or is it faster to do the string manipulation yourself manually? Which is quicker? 1) $insert = 'To Be';...
17
by: Chad Myers | last post by:
I've been perf testing an application of mine and I've noticed that there are a lot (and I mean A LOT -- megabytes and megabytes of 'em) System.String instances being created. I've done some...
37
by: jortizclaver | last post by:
Hi, I'm about to develop a new framework for my corporative applications and my first decision point is what kind of strings to use: std::string or classical C char*. Performance in my system...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.