From 3d6ebe55b2201b6ec8debff7a56aaf0b36bbabfe Mon Sep 17 00:00:00 2001 From: yv01p Date: Sun, 7 Dec 2025 21:43:39 +0000 Subject: [PATCH] perf: add benchmarks for StringExtensions methods to optimize MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- .../StringExtensionsBenchmarks.cs | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/Umbraco.Tests.Benchmarks/StringExtensionsBenchmarks.cs b/tests/Umbraco.Tests.Benchmarks/StringExtensionsBenchmarks.cs index 4f4a73c2c6..cbf67e186f 100644 --- a/tests/Umbraco.Tests.Benchmarks/StringExtensionsBenchmarks.cs +++ b/tests/Umbraco.Tests.Benchmarks/StringExtensionsBenchmarks.cs @@ -2,6 +2,7 @@ using System.Globalization; using System.Runtime.InteropServices; using BenchmarkDotNet.Attributes; using Umbraco.Cms.Core; +using Umbraco.Extensions; namespace Umbraco.Tests.Benchmarks; @@ -254,4 +255,28 @@ public class StringExtensionsBenchmarks // | SplitToStackSpansWithoutEmptyCheckReversingListAsSpan | 20.47 us | 0.290 us | 0.257 us | 2.7161 | 16.73 KB | // | SplitToStackSpansWithoutEmptyCheck | 20.60 us | 0.315 us | 0.280 us | 2.7161 | 16.73 KB | // | SplitToStackSpansWithEmptyCheck | 20.57 us | 0.308 us | 0.288 us | 2.7161 | 16.73 KB | + + private const string HtmlTestString = "

Hello world

"; + private const string WhitespaceTestString = "Hello world\t\ntest string"; + private const string FilePathTestString = "path/to/some/file.extension?query=param"; + private const string NonAlphanumericTestString = "hello-world_test!@#$%^&*()123"; + + [Benchmark] + public string StripWhitespace_Benchmark() => WhitespaceTestString.StripWhitespace(); + + [Benchmark] + public string GetFileExtension_Benchmark() => FilePathTestString.GetFileExtension(); + + [Benchmark] + public string StripHtml_Benchmark() => HtmlTestString.StripHtml(); + + [Benchmark] + public bool IsLowerCase_Benchmark() => 'a'.IsLowerCase(); + + [Benchmark] + public bool IsUpperCase_Benchmark() => 'A'.IsUpperCase(); + + [Benchmark] + public string ReplaceNonAlphanumericChars_String_Benchmark() + => NonAlphanumericTestString.ReplaceNonAlphanumericChars("-"); }