Hello everyone;
Recently I came across a situation that made me re-evaluate how I measure script efficiency.
Up to now, as rule of thumb, I have used the debug output file's size as a way to quickly see how much text is generated by a script, and use that value as a benchmark of that script's overall efficiency.
If, by tweaking some lines or trimming some steps, I can get -for the same search input and same results- a smaller debug file, I consider it as leaner, and therefore better, script.
While testing a particular script, I had written an IfVar condition that would run several steps more if enabled; however the debug output file size was actually smaller (in a measurable amount) with the option enabled than with it disabled, despite one having many tens of steps more than the other.
This got me thinking on what makes a script efficient and how to perform a valid benchmark.
The following is unrelated to the above example; but take this example script:
json_select "country"
OutputTo "variable1"
SayNChars 1
OutputTo "variable2"
SayNChars 1
RegexpReplace "^.*" "aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ"
OutputTo "country_CAPS"
FindInLine "%variable1%"
SayNChars 1
GotoChar 1
FindInLine "%variable2%"
SayNChars 1
Set "variable1" ""
Set "variable2" ""
This example can be used to convert ISO 3166-1 alpha-2 2-letter country codes from lower to uppercase.
This next example does exactly the same, but with a difference:
json_select "country"
OutputTo "variable1"
SayNChars 1
OutputTo "variable2"
SayNChars 1
RegexpReplace "^.*" "aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZaAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ"
OutputTo "country_CAPS"
SayRegexp "%variable1%"
SayRegexp "%variable2%"
Set "variable1" ""
Set "variable2" ""
In the first example, the conversion is achieved in 14 steps, and uses regex once.
In the 2nd example, the conversion is achieved in 13 steps, but uses regex 3 times, and on a longer string.
What I'm trying to understand is this:
Is the one step saved by using multiple instances of regex somehow nullified by the extra resource load of using regex (and on a longer string, which will "fatten" a debug output file)?
Of course, in one or 2 instances this is moot; but in several dozens -or hundreds- of repetitions, a script with less steps may not be faster (more efficient?) than one with more steps, but with "simpler" commands.
Has anyone came across a similar situation before?
What's your opinion? How to best evaluate a script?
Thank you in advance.







