I've never seen -match
test that much faster than -like
, if at all. Normally I see -like
at about the same or better speed.
But I never rely on one test instance, I usually run through about 10K reps of each.
If your're looking for performance, always prefer string methods if they'll meet the requirements:
$string = '123abc'
(measure-command {
for ($i=0;$i -lt 1e5;$i++)
{$string.contains('3ab')}
}).totalmilliseconds
(measure-command {
for ($i=0;$i -lt 1e5;$i++)
{$string -like '*3ab*'}
}).totalmilliseconds
(measure-command {
for ($i=0;$i -lt 1e5;$i++)
{$string -match '3ab'}
}).totalmilliseconds
265.3494
586.424
646.4878
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…