473,413 Members | 1,755 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,413 software developers and data experts.

string.Split() performant ?

Is string.Split() performant to a degree that there's no point in trying to
write code to improve on its performance ?

Jun 27 '08 #1
7 2908
On Sat, 24 May 2008 16:37:31 -0700, John A Grandy
<johnagrandy@g-mail-dot-comwrote:
Is string.Split() performant to a degree that there's no point in trying
to write code to improve on its performance ?
I would expect so. But if it's important to you, you can always test its
performance yourself to determine for sure.

I certainly wouldn't waste any time writing my own implementation until
I'd proved that my program was spending an inordinate amount of time in
the String.Split() method.

Pete
Jun 27 '08 #2
Hi Peter, and thanks for the response.

What about string.Replace() ... ?

Same answer ?

"Peter Duniho" <Np*********@nnowslpianmk.comwrote in message
news:op***************@petes-computer.local...
On Sat, 24 May 2008 16:37:31 -0700, John A Grandy
<johnagrandy@g-mail-dot-comwrote:
>Is string.Split() performant to a degree that there's no point in trying
to write code to improve on its performance ?

I would expect so. But if it's important to you, you can always test its
performance yourself to determine for sure.

I certainly wouldn't waste any time writing my own implementation until
I'd proved that my program was spending an inordinate amount of time in
the String.Split() method.

Pete
Jun 27 '08 #3
John A Grandy wrote:
Is string.Split() performant to a degree that there's no point in trying
to write code to improve on its performance ?
In general you should expect that MS has optimized
all the mostly used methods. I am sure that they run
profilers on .NET apps and see where in the library
there are bottlenecks.

A quick look at the source code gives me the impression that
the code is fast but use some memory.

Given that I find it very unlikely that you will be
able to write some split code that will increase
your app code measurable. It is much more likely
that you will be able to increase maintenance cost !

Arne
Jun 27 '08 #4
On Sat, 24 May 2008 17:11:32 -0700, John A Grandy
<johnagrandy@g-mail-dot-comwrote:
Hi Peter, and thanks for the response.

What about string.Replace() ... ?

Same answer ?
I would reply with basically the same answer for nearly every method in
the .NET Framework. Especially the part about not worrying about it until
you've proved it's a performance bottleneck.

There are certainly dumb, inefficient ways to do things in .NET. But
assuming you're putting the basic building-blocks together correctly, you
are unlikely to find some specific method in some specific .NET class that
performs so poorly it justifies writing your own version before you've
done some actual performance measurements to show that it's a signficant
part of whatever performance problem you may be experiencing.

Pete
Jun 27 '08 #5
How can I use a profiler ( e.g. RedGate ANTS Profiler ) to breakdown
relative performance of method calls inside giant iterations ? ( i.e.
implement 3 different algorithms and/or coding techniques and see which one
is taking the least time on avg per iteration )
"Peter Duniho" <Np*********@nnowslpianmk.comwrote in message
news:op***************@petes-computer.local...
On Sat, 24 May 2008 17:11:32 -0700, John A Grandy
<johnagrandy@g-mail-dot-comwrote:
>Hi Peter, and thanks for the response.

What about string.Replace() ... ?

Same answer ?

I would reply with basically the same answer for nearly every method in
the .NET Framework. Especially the part about not worrying about it until
you've proved it's a performance bottleneck.

There are certainly dumb, inefficient ways to do things in .NET. But
assuming you're putting the basic building-blocks together correctly, you
are unlikely to find some specific method in some specific .NET class that
performs so poorly it justifies writing your own version before you've
done some actual performance measurements to show that it's a signficant
part of whatever performance problem you may be experiencing.

Pete
Jun 27 '08 #6
On Sat, 24 May 2008 17:55:33 -0700, John A Grandy
<johnagrandy@g-mail-dot-comwrote:
How can I use a profiler ( e.g. RedGate ANTS Profiler ) to breakdown
relative performance of method calls inside giant iterations ? ( i.e.
implement 3 different algorithms and/or coding techniques and see which
one is taking the least time on avg per iteration )
I admit, I cannot advise you on the use of any specific profiler. It's
been many years since I needed to do intensive profiling work, and surely
the tools have changed a lot since then.

But I'm sure they still offer the same basic options: sampling vs.
instrumented, and using either method they will report things like
percentage and actual time spent in a specific method. This information
will allow you to see whether in fact improving the speed of the
String.Replace() method would help your program run faster.

When I need to measure the speed of things today, it's usually pretty
simply stuff, and I just use the Stopwatch class to find out how much time
specific sections of my code are taking.

Pete
Jun 27 '08 #7
On May 25, 1:11 am, "John A Grandy" <johnagrandy@g-mail-dot-com>
wrote:
Hi Peter, and thanks for the response.

What about string.Replace() ... ?

Same answer ?
Modulo the observation that StringBuilder.Replace may be a better fit
for your application (if you do multiple replaces on the same string,
then string.Replace will generate lots of different strings, whereas
the StringBuilder one won't), almost certainly yes.

It does depend what your application is. My guess is that the
framework is optimized for Split/Replace on strings a few k's long.
If your data is 100 MBytes, there may be other operations (like
splitting in place), that would be worthwhile.
>
"Peter Duniho" <NpOeStPe...@nnowslpianmk.comwrote in message

news:op***************@petes-computer.local...
On Sat, 24 May 2008 16:37:31 -0700, John A Grandy
<johnagrandy@g-mail-dot-comwrote:
Is string.Split() performant to a degree that there's no point in trying
to write code to improve on its performance ?
I would expect so. But if it's important to you, you can always test its
performance yourself to determine for sure.
I certainly wouldn't waste any time writing my own implementation until
I'd proved that my program was spending an inordinate amount of time in
the String.Split() method.
Pete
Jun 27 '08 #8

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

Similar topics

5
by: Stu Cazzo | last post by:
I have the following: String myStringArray; String myString = "98 99 100"; I want to split up myString and put it into myStringArray. If I use this: myStringArray = myString.split(" "); it...
11
by: Carlos Ribeiro | last post by:
Hi all, While writing a small program to help other poster at c.l.py, I found a small inconsistency between the handling of keyword parameters of string.split() and the split() method of...
2
by: Holysmoke | last post by:
Hi, I want to split a big string by nymber of characters. for eg., if total length of the string is 80 and I want to split by each 10 characters and get 8 lines of output. I written a...
5
by: CJM | last post by:
In an application I'm working the user has the opportunity to record the despatching of one or more items with serial numbers. For each item they despatch, they have to chose the serial no that...
6
by: Senthil | last post by:
Code ---------------------- string Line = "\"A\",\"B\",\"C\",\"D\""; string Line2 = Line.Replace("\",\"","\"\",\"\""); string CSVColumns = Line2.Split("\",\"".ToCharArray());
19
by: David Logan | last post by:
We need an additional function in the String class. We need the ability to suppress empty fields, so that we can more effectively parse. Right now, multiple whitespace characters create multiple...
3
by: Hetal Shah | last post by:
It is a C# code. I have a string like, one||two||three I want to split it into one, two and three. string str = "one||two||three"; string myStrs = str.Split("||");
5
by: kurt sune | last post by:
The code: Dim aLine As String = "cat" & vbNewLine & "dog" & vbNewLine & "fox" & vbNewLine Dim csvColumns1 As String() = aLine.Split(vbNewLine, vbCr, vbLf) Dim csvColumns2 As String() =...
12
by: John | last post by:
Hi I have a multi-line address field which has each line separated by CRLF. How can I split this field into individual strings using crlf as separator? Thanks Regards
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.