In my case, I have to remove any line containing "0.000000" from input
string.
In below case, it takes about 100 ms for 2k size input string.
Regex.Replace(inputString, ".*0\\.000000.*\n", "");
I want to optimize it, so i make a static member instance instead of
using static func of Regex;
static Regex filter= new Regex(".*0\\.000000.*\n",
RegexOptions.Compiled);
And use the static instance to replace the string.
filter.Replace(inputString, "");
Now, it takes about 200 ms. The platform is .net 1.1.
I don't understand why the non-static member function is slower thant
static one. The static function has to compile the regular expression
each time, right?
Is there any better solution to remove substring of specific pattern?
Perhaps I have to write my code to do it.
Thanks,
-Morgan 4 3101
Morgan,
To make regex faster try to avoid it by using a replace or an other method.
Regex is approx. 100 times slower in simple replacements than by instance
"replace".
(This will be gained again in complex situation where you would have to do a
lot of replacements of course)
I hope this helps,
Cor
"Morgan Cheng" <mo************@gmail.comschreef in bericht
news:11********************@k70g2000cwa.googlegrou ps.com...
In my case, I have to remove any line containing "0.000000" from input
string.
In below case, it takes about 100 ms for 2k size input string.
Regex.Replace(inputString, ".*0\\.000000.*\n", "");
I want to optimize it, so i make a static member instance instead of
using static func of Regex;
static Regex filter= new Regex(".*0\\.000000.*\n",
RegexOptions.Compiled);
And use the static instance to replace the string.
filter.Replace(inputString, "");
Now, it takes about 200 ms. The platform is .net 1.1.
I don't understand why the non-static member function is slower thant
static one. The static function has to compile the regular expression
each time, right?
Is there any better solution to remove substring of specific pattern?
Perhaps I have to write my code to do it.
Thanks,
-Morgan
Morgan Cheng <mo************@gmail.comwrote:
In my case, I have to remove any line containing "0.000000" from input
string.
In below case, it takes about 100 ms for 2k size input string.
Regex.Replace(inputString, ".*0\\.000000.*\n", "");
I want to optimize it, so i make a static member instance instead of
using static func of Regex;
static Regex filter= new Regex(".*0\\.000000.*\n",
RegexOptions.Compiled);
And use the static instance to replace the string.
filter.Replace(inputString, "");
Now, it takes about 200 ms. The platform is .net 1.1.
I don't understand why the non-static member function is slower thant
static one. The static function has to compile the regular expression
each time, right?
Is there any better solution to remove substring of specific pattern?
Perhaps I have to write my code to do it.
I would try using a StringReader, read the data line by line, and
append any line which doesn't contain 0.000000 - simple string
operations. If you could provide a test program you've used to gather
your performance data, we could experiment a bit.
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Cor Ligthert [MVP] 写道:
Morgan,
To make regex faster try to avoid it by using a replace or an other method.
Do you mean it is not recommeded to trim string with Regex?
So, the best way for is to code manually handling the string?
Regex is approx. 100 times slower in simple replacements than by instance
"replace".
(This will be gained again in complex situation where you would have to do a
lot of replacements of course)
I hope this helps,
Cor
"Morgan Cheng" <mo************@gmail.comschreef in bericht
news:11********************@k70g2000cwa.googlegrou ps.com...
In my case, I have to remove any line containing "0.000000" from input
string.
In below case, it takes about 100 ms for 2k size input string.
Regex.Replace(inputString, ".*0\\.000000.*\n", "");
I want to optimize it, so i make a static member instance instead of
using static func of Regex;
static Regex filter= new Regex(".*0\\.000000.*\n",
RegexOptions.Compiled);
And use the static instance to replace the string.
filter.Replace(inputString, "");
Now, it takes about 200 ms. The platform is .net 1.1.
I don't understand why the non-static member function is slower thant
static one. The static function has to compile the regular expression
each time, right?
Is there any better solution to remove substring of specific pattern?
Perhaps I have to write my code to do it.
Thanks,
-Morgan
Morgan,
>Do you mean it is not recommeded to trim string with Regex? So, the best way for is to code manually handling the string?
If you can avoid Regex try that, but not in the case that you have to done a
lot of things for it, or make your code not readable for others anymore.
Than use Regex.
(And than you probably on the place that it performs in at least the same).
Just my opinion.
Cor
"Morgan Cheng" <mo************@gmail.comschreef in bericht
news:11**********************@b28g2000cwb.googlegr oups.com...
Cor Ligthert [MVP] ??:
Morgan,
To make regex faster try to avoid it by using a replace or an other
method.
Do you mean it is not recommeded to trim string with Regex?
So, the best way for is to code manually handling the string?
Regex is approx. 100 times slower in simple replacements than by instance
"replace".
(This will be gained again in complex situation where you would have to do
a
lot of replacements of course)
I hope this helps,
Cor
"Morgan Cheng" <mo************@gmail.comschreef in bericht
news:11********************@k70g2000cwa.googlegrou ps.com...
In my case, I have to remove any line containing "0.000000" from input
string.
In below case, it takes about 100 ms for 2k size input string.
Regex.Replace(inputString, ".*0\\.000000.*\n", "");
I want to optimize it, so i make a static member instance instead of
using static func of Regex;
static Regex filter= new Regex(".*0\\.000000.*\n",
RegexOptions.Compiled);
And use the static instance to replace the string.
filter.Replace(inputString, "");
Now, it takes about 200 ms. The platform is .net 1.1.
I don't understand why the non-static member function is slower thant
static one. The static function has to compile the regular expression
each time, right?
Is there any better solution to remove substring of specific pattern?
Perhaps I have to write my code to do it.
Thanks,
-Morgan
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Jon Maz |
last post by:
Hi All,
Am getting frustrated trying to port the following (pretty simple) function
to CSharp. The problem is that I'm lousy at Regular Expressions....
//from...
|
by: bill tie |
last post by:
I'd appreciate it if you could advise.
1. How do I replace "\" (backslash) with anything?
2. Suppose I want to replace
(a) every occurrence of characters "a", "b", "c", "d" with "x",
(b)...
|
by: Greg Collins [InfoPath MVP] |
last post by:
I couldn't find anything in my searches... I'm wondering if there's a Regex (with or without additional C# code) that can convert a either "lowerCamelCase" or "UpperCamelCase" into a proper "Title...
|
by: Extremest |
last post by:
I know there are ways to make this a lot faster. Any
newsreader does this in seconds. I don't know how they do
it and I am very new to c#. If anyone knows a faster way
please let me know. All...
|
by: Extremest |
last post by:
I have a huge regex setup going on. If I don't do each one by itself
instead of all in one it won't work for. Also would like to know if
there is a faster way tried to use string.replace with all...
|
by: jwgoerlich |
last post by:
Hello group,
I am working on a query string class. The purpose is to parse
name-value pairs from incoming text. Currently, I am using the Regex
code below. I have two questions.
First, the...
|
by: =?Utf-8?B?U2VyZ2V5IFBvYmVyZXpvdnNraXk=?= |
last post by:
Hi,
I need to replace double quotes inside the text from the database with " to
correctly display my text. I was trying to use Regex to perform such a task:
Regex.Replace(text, "", """)
to...
|
by: V S Rawat |
last post by:
I was trying to use back-to-back replace functions to convert a url:
str1 =
str.replace("%2F","/").replace("%3F","?").replace("%3D","=").replace("%2
6","&");
It didn't replace all 4 types of...
|
by: seberino |
last post by:
I'm looking over the docs for the re module and can't find how to
"NOT" an entire regex.
For example.....
How make regex that means "contains regex#1 but NOT regex#2" ?
Chris
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: DJRhino |
last post by:
Was curious if anyone else was having this same issue or not....
I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: Aliciasmith |
last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
|
by: NeoPa |
last post by:
Hello everyone.
I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report).
I know it can be done by selecting :...
|
by: nia12 |
last post by:
Hi there,
I am very new to Access so apologies if any of this is obvious/not clear.
I am creating a data collection tool for health care employees to complete. It consists of a number of...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
|
by: isladogs |
last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, Mike...
|
by: GKJR |
last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...
| |