No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

UnsafeStreamPerformanceTests.cs 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. using NUnit.Framework;
  2. using System;
  3. using Unity.Burst;
  4. using Unity.Collections;
  5. using Unity.Collections.LowLevel.Unsafe;
  6. using Unity.Jobs;
  7. using Unity.PerformanceTesting;
  8. namespace Unity.Collections.PerformanceTests
  9. {
  10. internal class UnsafeStreamPerformanceTests
  11. {
  12. [BurstCompile]
  13. private class Pointers
  14. {
  15. [BurstCompile(CompileSynchronously = true)]
  16. public static void StreamWrite(ref UnsafeStream stream, int numElements)
  17. {
  18. var writer = stream.AsWriter();
  19. for (int i = 0; i < numElements; ++i)
  20. {
  21. writer.Write(i);
  22. }
  23. }
  24. public delegate void StreamWriteDelegate(ref UnsafeStream stream, int numElements);
  25. }
  26. [Test, Performance]
  27. [Category("Performance")]
  28. public void UnsafeStream_Performance_Write()
  29. {
  30. const int numElements = 16 << 10;
  31. var stream = new UnsafeStream(1, Allocator.Persistent);
  32. var writer = stream.AsWriter();
  33. Measure.Method(() =>
  34. {
  35. for (int i = 0; i < numElements; ++i)
  36. {
  37. writer.Write(i);
  38. }
  39. })
  40. .WarmupCount(100)
  41. .MeasurementCount(1000)
  42. .Run();
  43. stream.Dispose();
  44. }
  45. [Test, Performance]
  46. [Category("Performance")]
  47. public void UnsafeStream_Performance_Write_Burst()
  48. {
  49. const int numElements = 16 << 10;
  50. var stream = new UnsafeStream(1, Allocator.Persistent);
  51. var funcPtr = BurstCompiler.CompileFunctionPointer<Pointers.StreamWriteDelegate>(Pointers.StreamWrite);
  52. Measure.Method(() => { funcPtr.Invoke(ref stream, numElements); })
  53. .WarmupCount(100)
  54. .MeasurementCount(1000)
  55. .Run();
  56. stream.Dispose();
  57. }
  58. }
  59. }