Merge remote-tracking branch 'origin/v10/dev' into v11/dev
# Conflicts: # src/Umbraco.Core/Routing/UmbracoRequestPaths.cs
This commit is contained in:
3626
tests/Umbraco.Tests.Benchmarks/OldUtf8ToAsciiConverter.cs
Normal file
3626
tests/Umbraco.Tests.Benchmarks/OldUtf8ToAsciiConverter.cs
Normal file
File diff suppressed because it is too large
Load Diff
108
tests/Umbraco.Tests.Benchmarks/ShortStringHelperBenchmarks.cs
Normal file
108
tests/Umbraco.Tests.Benchmarks/ShortStringHelperBenchmarks.cs
Normal file
@@ -0,0 +1,108 @@
|
||||
using System;
|
||||
using BenchmarkDotNet.Attributes;
|
||||
using Umbraco.Cms.Core.Strings;
|
||||
using Umbraco.Tests.Benchmarks.Config;
|
||||
|
||||
namespace Umbraco.Tests.Benchmarks;
|
||||
|
||||
[QuickRunWithMemoryDiagnoserConfig]
|
||||
public class ShortStringHelperBenchmarks
|
||||
{
|
||||
private DefaultShortStringHelper _shortStringHelper;
|
||||
|
||||
private string _input;
|
||||
|
||||
[GlobalSetup]
|
||||
public void Setup()
|
||||
{
|
||||
_shortStringHelper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig());
|
||||
_input = "This is a 🎈 balloon";
|
||||
}
|
||||
|
||||
[Benchmark(Baseline = true)]
|
||||
public void ToUrlSegment()
|
||||
{
|
||||
_shortStringHelper.CleanStringForUrlSegment(_input);
|
||||
}
|
||||
|
||||
/*[Benchmark(Baseline = true)]
|
||||
public string OldAsciString()
|
||||
{
|
||||
return OldUtf8ToAsciiConverter.ToAsciiString(_input);
|
||||
}
|
||||
|
||||
|
||||
[Benchmark]
|
||||
public string NewAsciString()
|
||||
{
|
||||
return Utf8ToAsciiConverter.ToAsciiString(_input);
|
||||
}*/
|
||||
|
||||
#region SurrogatePairs
|
||||
|
||||
/*[Benchmark(Baseline = true)]
|
||||
public string RemoveSurrogatePairs()
|
||||
{
|
||||
var input = _input.ToCharArray();
|
||||
var output = new char[input.Length];
|
||||
var opos = 0;
|
||||
|
||||
for (var ipos = 0; ipos < input.Length; ipos++)
|
||||
{
|
||||
var c = input[ipos];
|
||||
if (char.IsSurrogate(c)) // ignore high surrogate
|
||||
{
|
||||
ipos++; // and skip low surrogate
|
||||
output[opos++] = '?';
|
||||
}
|
||||
else
|
||||
{
|
||||
output[opos++] = c;
|
||||
}
|
||||
}
|
||||
|
||||
return new string(output, 0, opos);
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public string RemoveNewSurrogatePairs()
|
||||
{
|
||||
var input = _input.AsSpan();
|
||||
Span<char> output = input.Length <= 1024 ? stackalloc char[input.Length] : new char[input.Length];
|
||||
var opos = 0;
|
||||
|
||||
for (var ipos = 0; ipos < input.Length; ipos++)
|
||||
{
|
||||
var c = input[ipos];
|
||||
if (char.IsSurrogate(c)) // ignore high surrogate
|
||||
{
|
||||
ipos++; // and skip low surrogate
|
||||
output[opos++] = '?';
|
||||
}
|
||||
else
|
||||
{
|
||||
output[opos++] = c;
|
||||
}
|
||||
}
|
||||
|
||||
return new string(output);
|
||||
}*/
|
||||
|
||||
#endregion
|
||||
|
||||
//| Method | Mean | Error | StdDev | Ratio | Gen 0 | Allocated |
|
||||
//|-----------------------------------:|---------:|---------:|--------:|------:|-------:|----------:|
|
||||
//| ToUrlSegment | 464.2 ns | 34.88 ns | 1.91 ns | 1.00 | 0.1627 | 512 B |
|
||||
//| ToUrlSegment (With below changes) | 455.7 ns | 26.83 ns | 1.47 ns | 1.00 | 0.1182 | 384 B |
|
||||
//| ToUrlSegment(CleanCodeString change| 420.6 ns | 64.06 ns | 3.51 ns | 1.00 | 0.0856 | 280 B |
|
||||
|
||||
//| Method | Mean | Error | StdDev | Ratio | Gen 0 | Allocated |
|
||||
//|------------------------ |---------:|----------:|---------:|------:|-------:|----------:|
|
||||
//| RemoveSurrogatePairs | 70.75 ns | 15.307 ns | 0.839 ns | 1.00 | 0.0610 | 192 B |
|
||||
//| RemoveNewSurrogatePairs | 58.44 ns | 7.297 ns | 0.400 ns | 0.83 | 0.0198 | 64 B |
|
||||
|
||||
//| Method | Mean | Error | StdDev | Ratio | Gen 0 | Allocated |
|
||||
//|-------------- |---------:|---------:|--------:|------:|-------:|----------:|
|
||||
//| OldAsciString | 181.4 ns | 11.50 ns | 0.63 ns | 1.00 | 0.0851 | 272 B |
|
||||
//| NewAsciString | 180.7 ns | 5.35 ns | 0.29 ns | 1.00 | 0.0450 | 64 B |
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using BenchmarkDotNet.Attributes;
|
||||
using Umbraco.Tests.Benchmarks.Config;
|
||||
|
||||
namespace Umbraco.Tests.Benchmarks;
|
||||
|
||||
[QuickRunWithMemoryDiagnoserConfig]
|
||||
public class StringReplaceFirstBenchmarks
|
||||
{
|
||||
[Params("Test string",
|
||||
"This is a test string that contains multiple test entries",
|
||||
"This is a string where the searched value is very far back. The system needs to go through all of this code before it reaches the test")]
|
||||
public string Text { get; set; }
|
||||
public string Search { get; set; }
|
||||
public string Replace { get; set; }
|
||||
|
||||
[GlobalSetup]
|
||||
public void Setup()
|
||||
{
|
||||
Search = "test";
|
||||
Replace = "release";
|
||||
}
|
||||
|
||||
[Benchmark(Baseline = true, Description = "Replace first w/ substring")]
|
||||
public string SubstringReplaceFirst()
|
||||
{
|
||||
var pos = Text.IndexOf(Search, StringComparison.InvariantCulture);
|
||||
|
||||
if (pos < 0)
|
||||
{
|
||||
return Text;
|
||||
}
|
||||
|
||||
return Text.Substring(0, pos) + Replace + Text.Substring(pos + Search.Length);
|
||||
}
|
||||
|
||||
[Benchmark(Description = "Replace first w/ span")]
|
||||
public string SpanReplaceFirst()
|
||||
{
|
||||
var spanText = Text.AsSpan();
|
||||
var pos = spanText.IndexOf(Search, StringComparison.InvariantCulture);
|
||||
|
||||
if (pos < 0)
|
||||
{
|
||||
return Text;
|
||||
}
|
||||
|
||||
return string.Concat(spanText[..pos], Replace.AsSpan(), spanText[(pos + Search.Length)..]);
|
||||
}
|
||||
|
||||
//| Method | Text | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Allocated |
|
||||
//|----------------------------- |--------------------- |----------:|---------:|---------:|------:|--------:|-------:|----------:|
|
||||
//| 'Replace first w/ substring' | Test string | 46.08 ns | 25.83 ns | 1.416 ns | 1.00 | 0.00 | - | - |
|
||||
//| 'Replace first w/ span' | Test string | 38.59 ns | 19.46 ns | 1.067 ns | 0.84 | 0.05 | - | - |
|
||||
//| | | | | | | | | |
|
||||
//| 'Replace first w/ substring' | This(...)test[134] | 407.89 ns | 52.08 ns | 2.855 ns | 1.00 | 0.00 | 0.1833 | 584 B |
|
||||
//| 'Replace first w/ span' | This(...)test[134] | 372.99 ns | 58.38 ns | 3.200 ns | 0.91 | 0.01 | 0.0941 | 296 B |
|
||||
//| | | | | | | | | |
|
||||
//| 'Replace first w/ substring' | This(...)tries[57] | 113.16 ns | 27.95 ns | 1.532 ns | 1.00 | 0.00 | 0.0961 | 304 B |
|
||||
//| 'Replace first w/ span' | This(...)tries[57] | 76.57 ns | 17.86 ns | 0.979 ns | 0.68 | 0.01 | 0.0455 | 144 B |
|
||||
}
|
||||
@@ -74,6 +74,7 @@ public class StringReplaceManyBenchmarks
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
short text, short replacement:
|
||||
|
||||
Reference in New Issue
Block a user