Sorry, the way you used $read is the bad thing, even if we do need the loop for multiple matches when using $read, it should never be used this way (getting each line and match with and if statement), look at this exemple.
Using this file ($mircdirtest.txt) :
aaaaaaaaaaaaaaaaaaaaaaaaaaaaa
bbbbbbbbbbbbbbbbbbbbbbbbbbbbb
ccccccccccccccccccccccccccccc
ddddddddddddddddddddddddddddd
eeeeeeeeeeeeeeeeeeeeeeeeeeeee
fffffffffffffffffffffffffffff
ggggggggggggggggggggggggggggg
hhhhhhhhhhhhhhhhhhhhhhhhhhhhh
iiiiiiiiiiiiiiiiiiiiiiiiiiiii
jjjjjjjjjjjjjjjjjjjjjjjjjjjjj
kkkkkkkkkkkkkkkkkkkkkkkkkkkkk
lllllllllllllllllllllllllllll
}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
mmmmmmmmmmmmmmmmmmmmmmmmmmmmm
nnnnnnnnnnnnnnnnnnnnnnnnnnnnn
ooooooooooooooooooooooooooooo
ppppppppppppppppppppppppppppp
qqqqqqqqqqqqqqqqqqqqqqqqqqqqq
rrrrrrrrrrrrrrrrrrrrrrrrrrrrr
sssssssssssssssssssssssssssss
ttttttttttttttttttttttttttttt
uuuuuuuuuuuuuuuuuuuuuuuuuuuuu
vvvvvvvvvvvvvvvvvvvvvvvvvvvvv
wwwwwwwwwwwwwwwwwwwwwwwwwwwww
xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
yyyyyyyyyyyyyyyyyyyyyyyyyyyyy
zzzzzzzzzzzzzzzzzzzzzzzzzzzzz
{{{{{{{{{{{{{{{{{{{{{{{{{{{{{
|||||||||||||||||||||||||||||
}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
And this code :
alias benchread {
var %t $ticks ,%a 1000,%l $lines(test.txt)
while (%a) {
var %b 1
while (%b <= %l) {
if (*}}}}}}}}}}* iswm $read(test.txt,n,%b)) noop match the file on line %b : $v1
; if ($regex($read(test.txt,n,%b),/\Q}}}}}}}}}}\E/i) noop match the file on line %b : $v1
inc %b
}
dec %a
}
echo -a in $calc($ticks - %t) ms
}
alias benchread1 {
var %t $ticks ,%a 1000
while (%a) {
var %l 1
while ($read(test.txt, wn, *}}}}}}}}}}*,%l) != $null) {
noop match the file on line $readn : $v1
%l = $readn + 1
}
; while ($read(test.txt, rn, /}}}}}}}}}}/i,%l) != $null) { noop match the file on line $readn : $v1 | %l = $readn +1 }
dec %a
}
echo -a in $calc($ticks - %t) ms
}
I get :
in 6178 ms
in 6209 ms
in 6177 ms
in 951 ms
in 921 ms
in 936 ms
for wildcard match and
in 6895 ms
in 6896 ms
in 6896 ms
-
in 1045 ms
in 1092 ms
in 1060 ms
for regex, as you can see using $read with the s or w switch and the N feature, that start searching at the Nth line of the file is far better
edit : this is just an exemple, of course /filter is better than a loop if multiple matches are to be done.