![]() |
Telelogic DOORS (steve huntington) | ![]() |
new topic :
profile :
search :
help :
dashboard :
calendar :
home
|
||
Latest News:
|
|
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 |
![]() |
![]()
|
![]() |
|
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 |
|
![]() |
|
![]() |
|
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 |
|
![]() |
|
![]() |
|
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 |
|
![]() |
|
![]() |
|
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 |
|
![]() |
Telelogic DOORS
» DXL Exchange
»
Regexp vs. string compare
|
![]() |
FuseTalk Standard Edition v3.2 - © 1999-2009 FuseTalk Inc. All rights reserved.