string parsing tScript speed questions.

Hey, I have two questions regarding improving the speed of my tScripts

  1. strcmp() vs. strmatch(): I frequently perform string comparisons to tell if two strings are exactly equal (currently using strcmp()), I am looking for a function similar to isEqual() which would stop parsing the the string as soon as a character doesn’t match. I assume strcmp() parses min(length(s1), length(s2)) characters at a minimum, which is more processing than I need most of the time. The only replacement function I could find is strmatch(), which I hope will process faster. Would strmatch() run faster than strcmp() if I am only looking to find out if they are equal or not quickly, or is there something like isEqual()?

  2. tab() vs tabc() and global vars : For coding cleanliness I have been using a lot of tabc() calls to reference various pieces of data, though I assume it requires the call to iterate through all columns and do string comparisons at each level, instead of tab() which I hope does random access into memory. I would like to maintain some code cleanliness so when I change the layout of the DAT, I don’t need to go through all the code and fix the indices. One way I thought to improve the speed would be to use Touch’s global variables, place all the correct indices in there, and use tab() functions instead of tabc(). My question is concerning how quickly variables are processed in tScript, would each tab(“dat”,$i,$col_idx_global_var) have to iterate through all the global vars doing string comparisons to evaluate $global_var, or does it use a hash table or something faster?

Thanks!

  1. strcmp is going to be way faster. strmatch does pattern matching.

  2. currently accessing variables iterate through the variable list instead of using a hash table.

Selina

I am not expert enough to speak authoritatively on this but, given the speed of modern computers, the speed gains are not worth worrying about in the case of tabc() vs tab(). being able to read your own code in 6 months time (let alone someone else’s) is a more dramatic speed increase.

but I could be wrong (I’ve made a career of it in fact).

rod.

One quick note on the first comment:
strcmp does in fact stop after finding two mismatched characters.
It only traverses the whole length if they are identical to that point.
But unless you are traversing very very long strings many many times a second I would guess any
optimization savings would be nominal in comparison to all the other cycles being spent running an overall system.
Cheers
Rob