Advertisement
Guest User

Untitled

a guest
Oct 28th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | None | 0 0
  1. using System;
  2. using BenchmarkDotNet.Running;
  3. using BenchmarkDotNet.Attributes;
  4. using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure;
  5.  
  6. namespace ConsoleApp2
  7. {
  8. public class Program
  9. {
  10. private static MemoryPool _pool;
  11. private static MemoryPoolIterator _iter;
  12. private static ulong _expectedResult;
  13. private static long _oldExpectedResult;
  14.  
  15. static Program()
  16. {
  17. var blockBytes = 0;
  18. _pool = new MemoryPool();
  19.  
  20. // Arrange
  21. _expectedResult = 0x0102030405060708UL;
  22. _oldExpectedResult = (long)_expectedResult;
  23. //var nonZeroData = 0xFF00FFFF0000FFFFUL;
  24. var nextBlockBytes = 8 - blockBytes;
  25.  
  26. var block = _pool.Lease();
  27. block.Start += 8;
  28. block.End = block.Start + blockBytes;
  29.  
  30. var nextBlock = _pool.Lease();
  31. nextBlock.Start += 8;
  32. nextBlock.End = nextBlock.Start + nextBlockBytes;
  33.  
  34. block.Next = nextBlock;
  35.  
  36. var bytes = BitConverter.GetBytes(_expectedResult);
  37. Buffer.BlockCopy(bytes, 0, block.Array, block.Start, blockBytes);
  38. Buffer.BlockCopy(bytes, blockBytes, nextBlock.Array, nextBlock.Start, nextBlockBytes);
  39.  
  40. // Fill in surrounding bytes with non-zero data
  41. //var nonZeroBytes = BitConverter.GetBytes(nonZeroData);
  42. //Buffer.BlockCopy(nonZeroBytes, 0, block.Array, block.Start - 8, 8);
  43. //Buffer.BlockCopy(nonZeroBytes, 0, block.Array, block.End, 8);
  44. //Buffer.BlockCopy(nonZeroBytes, 0, nextBlock.Array, nextBlock.Start - 8, 8);
  45. //Buffer.BlockCopy(nonZeroBytes, 0, nextBlock.Array, nextBlock.End, 8);
  46.  
  47. _iter = block.GetIterator();
  48. }
  49.  
  50. public static void Main(string[] args)
  51. {
  52. new Program().TestPeekLong();
  53. new Program().TestOldPeekLong();
  54. var summary = BenchmarkRunner.Run<Program>();
  55. Console.WriteLine(summary);
  56. }
  57.  
  58. [Benchmark]
  59. public void TestPeekLong()
  60. {
  61. ulong? result = _iter.PeekLong();
  62. if (result != _expectedResult)
  63. {
  64. throw new Exception();
  65. }
  66. }
  67.  
  68. [Benchmark]
  69. public void TestOldPeekLong()
  70. {
  71. long result = _iter.OldPeekLong();
  72. if (result != _oldExpectedResult)
  73. {
  74. throw new Exception();
  75. }
  76. }
  77. }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement