Welcome to Telelogic Product Support
  Home Downloads Knowledgebase Case Tracking Licensing Help Telelogic Passport
Telelogic DOORS (steve huntington)
Decrease font size
Increase font size
Topic Title: Regexp vs. string compare
Topic Summary: Which is faster?
Created On: 11-Sep-2007 20:01
Status: Post and Reply
Linear : Threading : Single : Branch
Search Topic Search Topic
Topic Tools Topic Tools
Quick Reply Quick Reply
Subscribe to this topic Subscribe to this topic
E-mail this topic to someone. E-mail this topic
Bookmark this topic Bookmark this topic
View similar topics View similar topics
View topic in raw text format. Print this topic.
 11-Sep-2007 20:01
User is offline View Users Profile Print this message


Chris Jones

Posts: 177
Joined: 1-Jul-2005

In our nightly metrics we have a routine that checks for suspect links, etc. But, it looks only at certain types of links (through certain link modules). So we have an if statement that used to look like this:

if(!matches("Link Mod to ignore 1", linkModName) && !matches("lm to ignore 2", linkModName) && ... )
{ //do stuff }

I read in the DXL manual that, "For repeated use, declaring and building a regular expression is more efficient" than matches, so I made a few global Regexp variables. But then I thought that it must be wasteful to be using regular expressions to look for a match when I know the exact string to match to. I changed over to using:

if((linkModName != NAME_TO_IGNORE) && (linkModName != NAME2_TO_IGNORE) && ... )


But now I wonder (again): considering all the memory issues with strings, is my second way really more efficient? Or does it even matter that much? I can't really distinguish a time difference when running it on a single module, although the script that uses the functions runs on a whole bunch every night.


Chris
Report this to a Moderator Report this to a Moderator
 11-Sep-2007 21:24
User is offline View Users Profile Print this message


David Pechacek

Posts: 674
Joined: 5-Dec-2006

Between trying to match against the exact string and using a regular expression, I don't think either will be better than the other. The strings you're comparing against are only put in the string table once. As are the strings you're trying to match to it regardless of using a regular expression or matching directly. So one isn't more or less memory efficient than the other.

If you really want to know, get the time at the start and end of the script doing it each way and see which takes longer.

-------------------------
David Pechacek
AAI Services Textron
dpechacek@sc-aaicorp.com
David.Pechacek@gmail.com
Report this to a Moderator Report this to a Moderator
 12-Sep-2007 09:33
User is offline View Users Profile Print this message


Reik Schroeder

Posts: 361
Joined: 28-Jul-2003

Hi Chris,

I think the string comparision must be much better (and faster) than using regular expression.
My experience with regular expressions in Doors shows that it is very usefull sometimes, but if you do not need it in your case I would suggest to not use it.

I would recommend to create a Skip list with names of Links Modules as keys. Then you can simply write something like "if (!find (slLinkModuleToIgnore, (linkModName)) { ...". The code becaomes much more readable

I think that this is the most flexible (the Skip list could be filled within an configuration area at beginning of script or in an include file) and fastest solution to your decribed problem.

Greetings
Reik

-------------------------
Evosoft GmbH
for Siemens Industry Sector


Berlin, Germany
Report this to a Moderator Report this to a Moderator
 14-Sep-2007 00:52
User is offline View Users Profile Print this message


Chris Jones

Posts: 177
Joined: 1-Jul-2005

That's a good idea, Reik! I've pondered about trying to match multiple strings before but for some reason never came up with using a Skip for it.

Thanks!
Chris
Report this to a Moderator Report this to a Moderator
Statistics
20925 users are registered to the Telelogic DOORS forum.
There are currently 2 users logged in.
The most users ever online was 15 on 15-Jan-2009 at 16:36.
There are currently 0 guests browsing this forum, which makes a total of 2 users using this forum.
You have posted 0 messages to this forum. 0 overall.

FuseTalk Standard Edition v3.2 - © 1999-2009 FuseTalk Inc. All rights reserved.