CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Regular Expressions:
Measuring the performance of a regex

 



vpadiri
Novice

Jul 7, 2009, 11:36 PM

Post #1 of 5 (3210 views)
Measuring the performance of a regex Can't Post

Hi all,

Is there any way to measure the performance of my regex?

Is there any way to get the no. of comparisons my regex has done to match the given string?

I there any way find where a particular regex is taking more time to match?

Thank you.


vikas.deep
User

Jul 8, 2009, 12:45 AM

Post #2 of 5 (3207 views)
Re: [vpadiri] Measuring the performance of a regex [In reply to] Can't Post

Hi vpa,
I see yesterday also you posted a similar question in Beginner's section.

Quote
Is there any way to measure the performance of my regex?

This has already being answered.

Quote
Is there any way to get the no. of comparisons my regex has done to match the given string?

I think this can be done using tr operator. But it depends what are you going to do with that regex and what is the regex, you see tr has some limitations and/ or some unique capabilities. See
http://perldoc.perl.org/perlop.html#Regexp-Quote-Like-Operators
and look out for
tr/search/replacement/cds

Quote
I there any way find where a particular regex is taking more time to match?

Much more time as compared to what do you have two regexs and you are comparing them or what please explain. "Much more time" is subjective it naturally demands as compared to what??

Quote
-For all my suggestions " I am sure someone else can do it in a better or elegant manner!"


vpadiri
Novice

Jul 8, 2009, 1:31 AM

Post #3 of 5 (3204 views)
Re: [vikas.deep] Measuring the performance of a regex [In reply to] Can't Post

Now I'll try to explain my question further,

If I have input records of the following form,
_____________________
Field1:my value1 Field2:new value2 Field3:more value3 Field4:test value4
_____________________

and I only need to get the values of Field1 and Field4.

If I use the regex
/^Field1:(.*) Field2:.* Field3:.* Field4:(.*)$/,
What are the no of comparisons for my input string (above) ?
Is there any better regex I can use?

Note: Assume that the values for fields in the input records will not contain the name "Field" in them.

Thank you


vpadiri
Novice

Jul 8, 2009, 2:55 AM

Post #4 of 5 (3202 views)
Re: [vpadiri] Measuring the performance of a regex [In reply to] Can't Post

Yes, I found it.

We can get the complete trace of matching a regular expression by using the following module.


use re 'debug';


vikas.deep
User

Jul 9, 2009, 3:24 AM

Post #5 of 5 (3190 views)
Re: [vpadiri] Measuring the performance of a regex [In reply to] Can't Post

Friend

I can't understand why you are not understanding you see posting similar questions even in different forums at same time is not welcome and you are posting similar questions in the same forum same time.

Again this (latest post) has been answered in beginners section.

Yet, I must add that if you have fixed length records, you should take a look at pack/unpack function at--. For fixed length records it is the easiest and the best way to do it.

http://perldoc.perl.org/functions/pack.html

and yes your regex will match only once with the string in question because that's the way you have designed it. Your regex starts at Field1 and ends at 4 after which there is nothing left in string.
This if you use "if loop"; if you want a number of comparisons use "for loop" and for infinite comparisons use "while loop".
In an if loop for each $_ when you say while(<$FileHandle>)it will match once.

Quote
-For all my suggestions " I am sure someone else can do it in a better or elegant manner!"

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives