//[InlineData(10, 1000, 4)] //[InlineData(10, 1000, 20)] public void Allocate_NonPooled(int?capacity, int?maxCapacity, int poolSize) { using (var test = new Perf.PoolBoy <Txt.StringBuilder>()) { Perf.Text.StringBuilder?priorStringBuilder = null; var created = 0; var contents = string.Join(',', Enumerable.Repeat("I want to test this out", 100)); do { var stringBuilder = new Perf.Text.StringBuilder(capacity, maxCapacity, poolSize: poolSize); stringBuilder.Append(contents); stringBuilder.IsPoolAllocated.Should().BeTrue(); if (priorStringBuilder.HasValue) { stringBuilder.performanceObject.Should().NotBeSameAs(priorStringBuilder.Value.performanceObject); } priorStringBuilder = stringBuilder; } while (++created < poolSize); var afterPoolSaturated = new Perf.Text.StringBuilder(capacity, maxCapacity, poolSize: poolSize); afterPoolSaturated.IsPoolAllocated.Should().BeFalse(); var afterPoolSaturatedAgain = new Perf.Text.StringBuilder(capacity, maxCapacity, poolSize: poolSize); afterPoolSaturatedAgain.IsPoolAllocated.Should().BeFalse(); } }
public void PoolSizeExceeded(int poolSize) { using (var test = new Perf.PoolBoy <Txt.StringBuilder>()) { Perf.Text.StringBuilder?priorStringBuilder = null; var created = 0; do { var stringBuilder = new Perf.Text.StringBuilder(poolSize: poolSize); stringBuilder.Append("I want to test this out."); stringBuilder.IsPoolAllocated.Should().BeTrue(); if (priorStringBuilder != null) { stringBuilder.performanceObject.Should().NotBeSameAs(priorStringBuilder.Value.performanceObject); } created++; priorStringBuilder = stringBuilder; } while (created < poolSize); var afterPoolSaturated = new Perf.Text.StringBuilder(poolSize: poolSize); afterPoolSaturated.IsPoolAllocated.Should().BeFalse(); } }
public void ObjectCapacityExceeded_RemovedFromPool() { int poolSize = 10; using (var test = new Perf.PoolBoy <Txt.StringBuilder>()) { var stringBuilder = new Perf.Text.StringBuilder(poolSize: poolSize); stringBuilder.Append("I want to test this out."); stringBuilder.IsPoolAllocated.Should().BeTrue(); stringBuilder.Dispose(); } }
public void ByCharacteristic_PoolKey_ShouldBeSame(int?capacity, int?maxCapacity, string poolKey) { using (var test = new Perf.PoolBoy <Txt.StringBuilder>()) { var stringBuilder = new Perf.Text.StringBuilder(capacity, maxCapacity, poolKey); stringBuilder.Append("I want to test this out."); stringBuilder.Dispose(DONOTCLEAR); test.ResetItemCounter(); var stringBuilder2 = new Perf.Text.StringBuilder(capacity, maxCapacity, poolKey); stringBuilder2.performanceObject.Should().BeSameAs(stringBuilder.performanceObject); stringBuilder2.ToString().Should().Be(stringBuilder.ToString()); } }