StringBuilder.replace(string,string) performance issues

P

Patrick Flanagan

I noticed high cpu usage with this function when it was used in a handler for
a SerialPort. Using the string.replace method fixes the issue, but using a
StringBuilder would be preferable to avoid generating garbage.

Has anyone else had performance issues with this function on the compact
framework? I've seen a few article that do comparisons between the
StringBuilder, string, and regex replace methods, but none have observed this
large performance gap I am seeing (cf vs. non-cf maybe?).
 
A

Alberto Silva, MVP

As in many scenarios, with .NET CF, and btw SQL Compact also, when
performance is a concern, you should test yourself, like doing 1000
iteractions with different methods, taking your conclusions about time
performance with the application compiled in Release mode, and then also
with the .NET CF Remote Perfomance Monitor and also the .NET CF CLR Profiler
to check between the different approaches which one require less GC.Collect,
that instantiates least objects, ... and then making your choice according
the results.

Alberto Silva

Patrick Flanagan said:
I noticed high cpu usage with this function when it was used in a handler
for
a SerialPort. Using the string.replace method fixes the issue, but using
a
StringBuilder would be preferable to avoid generating garbage.

Has anyone else had performance issues with this function on the compact
framework? I've seen a few article that do comparisons between the
StringBuilder, string, and regex replace methods, but none have observed
this
large performance gap I am seeing (cf vs. non-cf maybe?).

__________ Information from ESET NOD32 Antivirus, version of virus
signature database 4762 (20100111) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com

__________ Information from ESET NOD32 Antivirus, version of virus signature database 4762 (20100111) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top