I've run @Mass bench against another one that avoids
:for as I have the experience of extra costs associated to control statements.
My convoluted solution also does its best to avoid lambdas.
function! lh#time#bench_n2(n, F, ...) abort
if type(a:F) == type(function('type'))
let benchs = map(range(1, a:n), '[reltime()] + [a:F()] + [reltime()]')
let benchs = map(range(1, a:n), '[reltime()] + ['.a:F.'] + [reltime()]')
let res = benchs
call map(benchs, 'reltimefloat(reltime(v:val, v:val))')
let accu = 
call map(copy(benchs), 'add(accu, v:val + accu[-1])')
return [res, accu[-1]]
With the following on top of Mass' bench
echo lh#time#bench_n2(1000000, "matchstr('strpatingpattern', 'pattern') ")
echo lh#time#bench_n2(1000000, "match('strpatingpattern', 'pattern') ")
echo lh#time#bench_n2(1000000, "'strpatingpattern' =~ 'pattern' ")
echo lh#time#bench_n2(1000000, "'strpatingpattern' =~# 'pattern' ")
In the end, the results are a little bit more stable on my machine -- yet sometimes
=~ is a little bit faster than
=~#, sometimes it's the other way around. And also, now I'm sure it's convoluted and not necessary: Mass' simple solution is more than enough.
" Mass' bench in order to have an a idea
In conclusion, yeah
matchstr() is a little bit slower than
match() wich is a little bit slower than
=~, but honestly? I doubt you'll ever notice the difference, even when processing 100k or 1M tags. When you need
match() or ... extra services, use them. Otherwise use whatever you wish/prefer/like to test whether it matches.