public void Replace_Bad() { var segment = Payload.AsMemory(); var sw = Stopwatch.StartNew(); for (var index = 0; index < Count; index++) { LoopSpan(segment); } sw.Stop(); Logger.WriteLine($"Span: {sw.Elapsed}"); void LoopSpan(ReadOnlyMemory <char> payload) { Localizers.ForEach(kv => { payload = payload.Replace($"@(((MarkupString)Localizer[\"{kv.Key}\"].Value).ToString())".AsSpan(), kv.Value); payload = payload.Replace($"@((MarkupString)Localizer[\"{kv.Key}\"].Value)".AsSpan(), kv.Value); payload = payload.Replace($"@Localizer[\"{kv.Key}\"]".AsSpan(), kv.Value); }); payload = payload.Replace("@@".AsSpan(), "@"); payload = payload.Replace("<".AsSpan(), "<"); payload = payload.Replace(">".AsSpan(), ">"); } }
public void Replace_Ok() { var sw = Stopwatch.StartNew(); for (var index = 0; index < Count; index++) { Loop(Payload); } sw.Stop(); Logger.WriteLine($"String: {sw.Elapsed}"); void Loop(string payload) { Localizers.ForEach(kv => { payload = payload.Replace($"@(((MarkupString)Localizer[\"{kv.Key}\"].Value).ToString())", kv.Value); payload = payload.Replace($"@((MarkupString)Localizer[\"{kv.Key}\"].Value)", kv.Value); payload = payload.Replace($"@Localizer[\"{kv.Key}\"]", kv.Value); }); payload = payload.Replace("@@", "@"); payload = payload.Replace("<", "<"); payload = payload.Replace(">", ">"); } }