OMG! => I just found a super-fast method of concatenating strings in FileMaker!*
With "Insert Calculated Result" (append to variable) FileMaker concatenates strings in linear time O(n).
"Set Variable" on the other hand performs in quadratic time, O(n^2):
Compare:
- When concatenating 200 000 strings with "Set Variable" takes >3 minutes,
- with "Insert Calculated Result" it is finished in under 7 seconds!
Because:
Try it yourself:
Attached below is a little Benchmarking tool which I used to get these results.
Time to Change!
Please Share and spread the word!
"Happy"& " "& "String"& " "& "Concatenation" & "¶¶" & "MrWatson"
----------------------------
* The original entry was incorrectly posted here as an issue, and reposted here to make it easier to find, share + discuss
----------------------------
2018-08-15 MrW EDIT: Attached new fmBenchMark app, which is now fm16 and fm17 compatible.
Given previous tests that showed better performance for modifying data in variables instead of fields, (but not concatenation and using set field), these are surprising results.
It it would be interesting to see how a modified form of your script worked using set field instead of insert compares to your other results.
If a script only concatenates a few strings and does not loop over massive numbers of records, the resulting improvement is unlikely to be observable. I point this out because all of the “insert” script steps have more potentially troubling features than other steps that modify data in a field. Thus, I avoid using them without a compelling reason to do so. Your tests might just identify one more such reason.
”insert” steps, copy, paste, clear all can:
1) fail if the specified target field is removed from the layout.
2) can change layout focus—tripping triggers that run other scripts that might interfere. Not only now, but your future self or a fellow developer might unknowingly interfere with your script by adding such a trigger.
Of course, there are ways to guard against this, but those are steps that I don’t have to take if I don’t use these script steps.