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