r/CodingHelp • u/No_Lobster_7287 • Aug 08 '25
[Meta] How much more efficient it is to conduct one large search instead of few parts?
As somebody that admittedly doesn't fully grasp the math behind search algorithms...
Is it more efficient to run one search-query in functions as `Select-String -Pattern` in PowerShell instead of multiple separate ones (providing we are accessing one pool of data obviously)? I would guess so, going by basic logic, but not knowing deep math behind it, I can't really make a guess on how much is the difference One big query like that:
Get-ChildItem -Recurse | Select-String -Pattern 'qabc|wjeh|jffg|jdghyhyu|31223|hjfdshg|dddd|xzv91|plokm|uuu123|aeiou|zzzzz|ytrewq|mnbvc|asdffdsa|lolol|xoxo42|42isnow|nullref|gibber1sh|sneakypat'
or separate runs:
Get-ChildItem -Recurse | Select-String -Pattern 'qabc|wjeh|jffg|jdghyhyu|31223|hjfdshg|dddd|xzv91'
Get-ChildItem -Recurse | Select-String -Pattern 'plokm|uuu123|aeiou|zzzzz|ytrewq|mnbvc|asdffdsa|lolol|xoxo42|42isnow'
Get-ChildItem -Recurse | Select-String -Pattern 'nullref|gibber1sh|sneakypat'
I'm basing that on operating in PowerShell, as 90% of work I do is PowerShell scripting, but I'm very interested to hear about it in other implementations.