public void PoolSizeExceeded(int poolSize) { using (var test = new Perf.PoolBoy <Txt.RegularExpressions.Regex>()) { const string numbersRegexPattern = "[0-9]+"; Perf.Text.RegularExpressions.Regex?priorRegex = null; var created = 0; do { var regexNumbers = new Perf.Text.RegularExpressions.Regex(numbersRegexPattern, poolSize: poolSize); regexNumbers.IsPoolAllocated.Should().BeTrue(); if (priorRegex != null) { regexNumbers.performanceObject.Should().NotBeSameAs(priorRegex.Value.performanceObject); } created++; priorRegex = regexNumbers; } while (created < poolSize); var afterPoolSaturated = new Perf.Text.RegularExpressions.Regex(numbersRegexPattern, poolSize: poolSize); afterPoolSaturated.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 Allocate_NonPooled(int?capacity, int appends, int poolSize) { using (var test = new Perf.PoolBoy <System.Collections.Generic.List <string> >()) { Perf.Collection.Generic.List <string>?priorList = null; var created = 0; var contents = "0123456789"; do { var list = capacity.HasValue ? new Perf.Collection.Generic.List <string>(capacity.Value, poolSize: poolSize) : new Perf.Collection.Generic.List <string>(poolSize: poolSize); for (var i = 0; i < appends; i++) { list.Add(contents); } list.wrapperObject.IsPoolAllocated.Should().BeTrue(); if (priorList.HasValue) { list.performanceObject.Should().NotBeSameAs(priorList.Value.performanceObject); } priorList = list; } while (++created < poolSize); var afterPoolSaturated = capacity.HasValue ? new Perf.Collection.Generic.List <string>(capacity.Value, poolSize: poolSize) : new Perf.Collection.Generic.List <string>(poolSize: poolSize); afterPoolSaturated.wrapperObject.IsPoolAllocated.Should().BeFalse(); var afterPoolSaturatedAgain = capacity.HasValue ? new Perf.Collection.Generic.List <string>(capacity.Value, poolSize: poolSize) : new Perf.Collection.Generic.List <string>(poolSize: poolSize); afterPoolSaturatedAgain.wrapperObject.IsPoolAllocated.Should().BeFalse(); } }
//[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 WarmupPool() { // Creating first object will warm pool up. using (var test = new Perf.PoolBoy <Text.StringBuilder>()) { using (var stringBuilder = new Perf.Text.StringBuilder(Capacity, poolSize: PoolSize)) { // Access the wrapper object in order to create object pool. var wrapper = stringBuilder.wrapperObject; } } }
public void WarmupPool() { // Creating first object will warm pool up. using (var test = new Perf.PoolBoy <Text.RegularExpressions.Regex>()) { using (var regex = new Perf.Text.RegularExpressions.Regex("[0-9]+", poolSize: PoolSize)) { // Access the wrapper object in order to create object pool. var wrapper = regex.wrapperObject; } } }
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(); } }
//[Benchmark] public void BenchmarkPooled() { using (var test = new Perf.PoolBoy <Text.StringBuilder>()) { for (var i = 0; i < Iters; i++) { using (var stringBuilder = new Perf.Text.StringBuilder(Capacity, poolSize: PoolSize)) { for (var x = 0; x < Concats; x++) { stringBuilder.Append(stringAllocation); } } } } }
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()); } }
//[Benchmark] public void BenchmarkPooled() { using (var test = new Perf.PoolBoy <Text.StringBuilder>()) { for (var i = 0; i < Iters; i++) { using (var regex = new Perf.Text.RegularExpressions.Regex("[0-9]+", poolSize: PoolSize)) { for (var x = 0; x < Concats; x++) { regex.IsMatch(stringAllocation); } } } } }
public void SamePattern_SamePool(string poolKey) { using (var test = new Perf.PoolBoy <Txt.RegularExpressions.Regex>()) { const string numbersRegexPattern = "[0-9]+"; var regexNumbers = new Perf.Text.RegularExpressions.Regex(numbersRegexPattern, poolKey); var regexNumbers2 = new Perf.Text.RegularExpressions.Regex(numbersRegexPattern, poolKey); regexNumbers.IsPoolAllocated.Should().BeTrue(); regexNumbers2.IsPoolAllocated.Should().BeTrue(); regexNumbers2._objectPool.Should().BeSameAs(regexNumbers._objectPool); regexNumbers2.performanceObject.Should().NotBeSameAs(regexNumbers.performanceObject); } }
[InlineData(101, 100)] // Cap, no max public void ByCharacteristic_PoolKey_ShouldBeSame(int?capacity, int appends) { var contents = "0123456789"; using (var test = new Perf.PoolBoy <System.Collections.Generic.List <string> >()) { var list = capacity.HasValue ? new Perf.Collection.Generic.List <string>(capacity.Value) : new Perf.Collection.Generic.List <string>(0); for (var i = 0; i < appends; i++) { list.Add(contents); } list.Dispose(DONOTCLEAR); test.ResetItemCounter(); var list2 = capacity.HasValue ? new Perf.Collection.Generic.List <string>(capacity.Value) : new Perf.Collection.Generic.List <string>(); list2.performanceObject.Should().BeSameAs(list.performanceObject); list2.ToString().Should().Be(list.ToString()); } }