In order to gain performance on the StringBuilder operations, I tried to apply the object pooling.
But pooling the StringBuilder seems to be slower than the original usage on both net8 and net7.
What might cause the problem, any additional settings needed for benchmark dot net?
[MemoryDiagnoser] public class StringBuilderPoolPerformance { [Benchmark] public void WithoutPool() { for (int i = 0; i < 10000; i++) { var stringBuilder = new StringBuilder(); stringBuilder.Append("Hello World" + i); } } [Benchmark] public void WithPool() { var stringBuilderPool = new DefaultObjectPoolProvider().CreateStringBuilderPool(); for (var i = 0; i < 10000; i++) { var stringBuilder = stringBuilderPool.Get(); stringBuilder.Append("Hello World" + i); stringBuilderPool.Return(stringBuilder); } } } 