static void SpanSample()
{
var str
= "Times:10086";
var strSpan
= str
.AsSpan();
var sw
= new Stopwatch();
sw
.Start();
for (var j
= 0; j
< 1000000; j
++)
{
int.Parse(strSpan
.Slice(6));
}
sw
.Stop();
Console
.WriteLine("耗时" + sw
.ElapsedMilliseconds
);
sw
.Restart();
for (var j
= 0; j
< 1000000; j
++)
{
int.Parse(str
.Substring(6));
}
sw
.Stop();
Console
.WriteLine("耗时" + sw
.ElapsedMilliseconds
);
}
转载请注明原文地址:https://tech.qufami.com/read-19380.html