Last active
May 23, 2017 02:00
-
-
Save itn3000/5eacb7d7258207f98b63413ab05b6a1a to your computer and use it in GitHub Desktop.
ArrayPool.Rent vs new byte[] test(netcoreapp2.0-preview1)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Buffers; | |
namespace bufferpooltest | |
{ | |
class Program | |
{ | |
const int LoopCount = 100000000; | |
static void ArrayPoolTest(int loopCount, int bufferSize) | |
{ | |
var arrayPool = ArrayPool<byte>.Create(); | |
var sw = new System.Diagnostics.Stopwatch(); | |
sw.Start(); | |
for (int i = 0; i < loopCount; i++) | |
{ | |
var x = arrayPool.Rent(bufferSize); | |
if(i % DebugOutInterval == DebugOutInterval - 1) | |
{ | |
Console.WriteLine($"ArrayPoolTest: {i},{sw.Elapsed},{x.Length}"); | |
} | |
arrayPool.Return(x); | |
} | |
Console.WriteLine($"ArrayPoolTest: {loopCount},{bufferSize} {sw.Elapsed}"); | |
} | |
static void ArrayAllocTest(int loopCount, int bufferSize) | |
{ | |
var sw = new System.Diagnostics.Stopwatch(); | |
sw.Start(); | |
for (int i = 0; i < loopCount; i++) | |
{ | |
var x = new byte[bufferSize]; | |
if(i % DebugOutInterval == DebugOutInterval - 1) | |
{ | |
Console.WriteLine($"ArrayAlloclTest: {i},{sw.Elapsed},{x.Length}"); | |
} | |
} | |
Console.WriteLine($"ArrayAllocTest: {loopCount},{bufferSize} {sw.Elapsed}"); | |
} | |
static void Main(string[] args) | |
{ | |
var bufferSizes = new int[]{128,1024,2048,4096}; | |
foreach(var s in bufferSizes) | |
{ | |
ArrayAllocTest(LoopCount, s); | |
GC.Collect(); | |
ArrayPoolTest(LoopCount, s); | |
GC.Collect(); | |
} | |
Console.WriteLine("Hello World!"); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ArrayAlloclTest: 9999999,00:00:00.1106672,128 | |
ArrayAlloclTest: 19999999,00:00:00.2227236,128 | |
ArrayAlloclTest: 29999999,00:00:00.3317979,128 | |
ArrayAlloclTest: 39999999,00:00:00.4406508,128 | |
ArrayAlloclTest: 49999999,00:00:00.5490262,128 | |
ArrayAlloclTest: 59999999,00:00:00.6603859,128 | |
ArrayAlloclTest: 69999999,00:00:00.7692854,128 | |
ArrayAlloclTest: 79999999,00:00:00.8763516,128 | |
ArrayAlloclTest: 89999999,00:00:00.9873895,128 | |
ArrayAlloclTest: 99999999,00:00:01.1003446,128 | |
ArrayAllocTest: 100000000,128 00:00:01.1003733 | |
ArrayPoolTest: 9999999,00:00:00.4810451,128 | |
ArrayPoolTest: 19999999,00:00:00.9603920,128 | |
ArrayPoolTest: 29999999,00:00:01.4346641,128 | |
ArrayPoolTest: 39999999,00:00:01.9043537,128 | |
ArrayPoolTest: 49999999,00:00:02.3786909,128 | |
ArrayPoolTest: 59999999,00:00:02.8633888,128 | |
ArrayPoolTest: 69999999,00:00:03.3375458,128 | |
ArrayPoolTest: 79999999,00:00:03.8238313,128 | |
ArrayPoolTest: 89999999,00:00:04.3044378,128 | |
ArrayPoolTest: 99999999,00:00:04.7784071,128 | |
ArrayPoolTest: 100000000,128 00:00:04.7784300 | |
ArrayAlloclTest: 9999999,00:00:00.5434343,1024 | |
ArrayAlloclTest: 19999999,00:00:01.0657269,1024 | |
ArrayAlloclTest: 29999999,00:00:01.5931273,1024 | |
ArrayAlloclTest: 39999999,00:00:02.1295977,1024 | |
ArrayAlloclTest: 49999999,00:00:02.7581321,1024 | |
ArrayAlloclTest: 59999999,00:00:03.3733426,1024 | |
ArrayAlloclTest: 69999999,00:00:03.9318894,1024 | |
ArrayAlloclTest: 79999999,00:00:04.4597736,1024 | |
ArrayAlloclTest: 89999999,00:00:05.0034323,1024 | |
ArrayAlloclTest: 99999999,00:00:05.5356571,1024 | |
ArrayAllocTest: 100000000,1024 00:00:05.5356792 | |
ArrayPoolTest: 9999999,00:00:00.4730527,1024 | |
ArrayPoolTest: 19999999,00:00:00.9495306,1024 | |
ArrayPoolTest: 29999999,00:00:01.4159467,1024 | |
ArrayPoolTest: 39999999,00:00:01.8992200,1024 | |
ArrayPoolTest: 49999999,00:00:02.3675463,1024 | |
ArrayPoolTest: 59999999,00:00:02.8373386,1024 | |
ArrayPoolTest: 69999999,00:00:03.3215655,1024 | |
ArrayPoolTest: 79999999,00:00:03.7972639,1024 | |
ArrayPoolTest: 89999999,00:00:04.2863314,1024 | |
ArrayPoolTest: 99999999,00:00:04.7698559,1024 | |
ArrayPoolTest: 100000000,1024 00:00:04.7698804 | |
ArrayAlloclTest: 9999999,00:00:01.0020104,2048 | |
ArrayAlloclTest: 19999999,00:00:02.0195303,2048 | |
ArrayAlloclTest: 29999999,00:00:03.0236119,2048 | |
ArrayAlloclTest: 39999999,00:00:04.0987027,2048 | |
ArrayAlloclTest: 49999999,00:00:05.0835414,2048 | |
ArrayAlloclTest: 59999999,00:00:06.2099468,2048 | |
ArrayAlloclTest: 69999999,00:00:07.1976442,2048 | |
ArrayAlloclTest: 79999999,00:00:08.1790506,2048 | |
ArrayAlloclTest: 89999999,00:00:09.1467722,2048 | |
ArrayAlloclTest: 99999999,00:00:10.1357124,2048 | |
ArrayAllocTest: 100000000,2048 00:00:10.1357375 | |
ArrayPoolTest: 9999999,00:00:00.5265798,2048 | |
ArrayPoolTest: 19999999,00:00:01.0632286,2048 | |
ArrayPoolTest: 29999999,00:00:01.5375568,2048 | |
ArrayPoolTest: 39999999,00:00:02.0155721,2048 | |
ArrayPoolTest: 49999999,00:00:02.4838317,2048 | |
ArrayPoolTest: 59999999,00:00:02.9525738,2048 | |
ArrayPoolTest: 69999999,00:00:03.4228786,2048 | |
ArrayPoolTest: 79999999,00:00:03.8963465,2048 | |
ArrayPoolTest: 89999999,00:00:04.3658048,2048 | |
ArrayPoolTest: 99999999,00:00:04.8336355,2048 | |
ArrayPoolTest: 100000000,2048 00:00:04.8336581 | |
ArrayAlloclTest: 9999999,00:00:01.8774235,4096 | |
ArrayAlloclTest: 19999999,00:00:03.8640532,4096 | |
ArrayAlloclTest: 29999999,00:00:05.9720277,4096 | |
ArrayAlloclTest: 39999999,00:00:08.0498230,4096 | |
ArrayAlloclTest: 49999999,00:00:10.0782852,4096 | |
ArrayAlloclTest: 59999999,00:00:12.2521059,4096 | |
ArrayAlloclTest: 69999999,00:00:14.4667327,4096 | |
ArrayAlloclTest: 79999999,00:00:16.5709712,4096 | |
ArrayAlloclTest: 89999999,00:00:18.7097100,4096 | |
ArrayAlloclTest: 99999999,00:00:20.8527043,4096 | |
ArrayAllocTest: 100000000,4096 00:00:20.8527580 | |
ArrayPoolTest: 9999999,00:00:00.4666563,4096 | |
ArrayPoolTest: 19999999,00:00:00.9483300,4096 | |
ArrayPoolTest: 29999999,00:00:01.4235654,4096 | |
ArrayPoolTest: 39999999,00:00:01.9020009,4096 | |
ArrayPoolTest: 49999999,00:00:02.3731174,4096 | |
ArrayPoolTest: 59999999,00:00:02.8424418,4096 | |
ArrayPoolTest: 69999999,00:00:03.3059197,4096 | |
ArrayPoolTest: 79999999,00:00:03.7872849,4096 | |
ArrayPoolTest: 89999999,00:00:04.2522695,4096 | |
ArrayPoolTest: 99999999,00:00:04.7320734,4096 | |
ArrayPoolTest: 100000000,4096 00:00:04.7320985 | |
Hello World! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment