isladogs
Access MVP / VIP
- Local time
- Today, 02:23
- Joined
- Jan 14, 2017
- Messages
- 19,297
I added in @arnelgp's new code based on Regex and re-tested each 3 times.
I pasted 3 text strings of differing lengths into a table for testing
Firstly, with the ridiculously short string I used before
As before, there is very little difference in the results ... but with such a short string its easy enough to edit it manually!
And again, with the longer string I used before
Here arnel's new code is a clear winner
And once more with a much longer string of almost 12K characters:
Even more dramatic differences in this case with @arnelgp crowned as Regex King!
The outcomes are clearly significant in this set of tests
Both Regex versions are significantly faster and in particular arnel's version is particularly impressive in tems of speed for this set of tests.
I'll update my article with an additional example app based on some of these tests - probably just arnel's as he achieved both the fastest and slowest results of the largest sample

Nevertheless, my conclusions in the original article still stand.
For a simple task particularly with a small dataset, using Regex offers no speed advantages and may be overkill.
However, for a more complex task, especially with a large dataset to process, it clearly can offer real advantages
Of course, speed isn't the only factor here. For example, the additional time needed to devise a Regex solution to solve a specific task may outweigh the time it may save in terms of execution
I pasted 3 text strings of differing lengths into a table for testing
Firstly, with the ridiculously short string I used before
Code:
Test1 - Short String (19 chars)
1. MajP - Loop: ReplaceMultiSpace : Time Taken = 0.0859375 s
2. AGP - Loop: SngSpaceOnly : Time Taken = 0.078125 s
3. AGP Regex: OneSpaceOnly : Time Taken = 0.0546875 s
4. EBS17 : RegExReplace : Time Taken = 0.0859375 s
Test1 - Short String (19 chars)
1. MajP - Loop: ReplaceMultiSpace : Time Taken = 0.08203125 s
2. AGP - Loop: SngSpaceOnly : Time Taken = 0.078125 s
3. AGP Regex: OneSpaceOnly : Time Taken = 0.0546875 s
4. EBS17 : RegExReplace : Time Taken = 0.0859375 s
Test1 - Short String (19 chars)
1. MajP - Loop: ReplaceMultiSpace : Time Taken = 0.08203125 s
2. AGP - Loop: SngSpaceOnly : Time Taken = 0.07421875 s
3. AGP Regex: OneSpaceOnly : Time Taken = 0.0546875 s
4. EBS17 : RegExReplace : Time Taken = 0.0859375 s
As before, there is very little difference in the results ... but with such a short string its easy enough to edit it manually!
And again, with the longer string I used before
Code:
Test2 - Longer String (561 chars)
1. MajP - Loop: ReplaceMultiSpace : Time Taken = 0.5 s
2. AGP - Loop: SngSpaceOnly : Time Taken = 0.59765625 s
3. AGP Regex: OneSpaceOnly : Time Taken = 0.06640625 s
4. EBS17 : RegExReplace : Time Taken = 0.15625 s
Test2 - Longer String (561 chars)
1. MajP - Loop: ReplaceMultiSpace : Time Taken = 0.49609375 s
2. AGP - Loop: SngSpaceOnly : Time Taken = 0.59375 s
3. AGP Regex: OneSpaceOnly : Time Taken = 0.06640625 s
4. EBS17 : RegExReplace : Time Taken = 0.15625 s
Test2 - Longer String (561 chars)
1. MajP - Loop: ReplaceMultiSpace : Time Taken = 0.49609375 s
2. AGP - Loop: SngSpaceOnly : Time Taken = 0.59375 s
3. AGP Regex: OneSpaceOnly : Time Taken = 0.0625 s
4. EBS17 : RegExReplace : Time Taken = 0.16015625 s
Here arnel's new code is a clear winner
And once more with a much longer string of almost 12K characters:
Code:
Test3 - Even Longer String (12K chars)
1. MajP - Loop: ReplaceMultiSpace : Time Taken = 16.22265625 s
2. AGP - Loop: SngSpaceOnly : Time Taken = 22.16796875 s
3. AGP Regex: OneSpaceOnly : Time Taken = 0.16015625 s
4. EBS17 : RegExReplace : Time Taken = 1.1171875 s
Test3 - Even Longer String (12K chars)
1. MajP - Loop: ReplaceMultiSpace : Time Taken = 16.05078125 s
2. AGP - Loop: SngSpaceOnly : Time Taken = 23.18359375 s
3. AGP Regex: OneSpaceOnly : Time Taken = 0.171875 s
4. EBS17 : RegExReplace : Time Taken = 1.5625 s
Test3 - Even Longer String (12K chars)
1. MajP - Loop: ReplaceMultiSpace : Time Taken = 17.2265625 s
2. AGP - Loop: SngSpaceOnly : Time Taken = 23.10546875 s
3. AGP Regex: OneSpaceOnly : Time Taken = 0.16796875 s
4. EBS17 : RegExReplace : Time Taken = 1.1328125 s
Even more dramatic differences in this case with @arnelgp crowned as Regex King!
The outcomes are clearly significant in this set of tests
Both Regex versions are significantly faster and in particular arnel's version is particularly impressive in tems of speed for this set of tests.
I'll update my article with an additional example app based on some of these tests - probably just arnel's as he achieved both the fastest and slowest results of the largest sample
Nevertheless, my conclusions in the original article still stand.
For a simple task particularly with a small dataset, using Regex offers no speed advantages and may be overkill.
However, for a more complex task, especially with a large dataset to process, it clearly can offer real advantages
Of course, speed isn't the only factor here. For example, the additional time needed to devise a Regex solution to solve a specific task may outweigh the time it may save in terms of execution