study/first_study/Library/PackageCache/com.unity.collections@aea9d3bd5e19/Unity.Collections.PerformanceTests/UnsafeStreamPerformanceTests.cs
jh04010421 739d49f1a0 Unity | 2026.01.20
수업 실습 파일
2026-01-20 11:01:57 +09:00

73 lines
2.0 KiB
C#

using NUnit.Framework;
using System;
using Unity.Burst;
using Unity.Collections;
using Unity.Collections.LowLevel.Unsafe;
using Unity.Jobs;
using Unity.PerformanceTesting;
namespace Unity.Collections.PerformanceTests
{
internal class UnsafeStreamPerformanceTests
{
[BurstCompile]
private class Pointers
{
[BurstCompile(CompileSynchronously = true)]
public static void StreamWrite(ref UnsafeStream stream, int numElements)
{
var writer = stream.AsWriter();
for (int i = 0; i < numElements; ++i)
{
writer.Write(i);
}
}
public delegate void StreamWriteDelegate(ref UnsafeStream stream, int numElements);
}
[Test, Performance]
[Category("Performance")]
public void UnsafeStream_Performance_Write()
{
const int numElements = 16 << 10;
var stream = new UnsafeStream(1, Allocator.Persistent);
var writer = stream.AsWriter();
Measure.Method(() =>
{
for (int i = 0; i < numElements; ++i)
{
writer.Write(i);
}
})
.WarmupCount(100)
.MeasurementCount(1000)
.Run();
stream.Dispose();
}
[Test, Performance]
[Category("Performance")]
public void UnsafeStream_Performance_Write_Burst()
{
const int numElements = 16 << 10;
var stream = new UnsafeStream(1, Allocator.Persistent);
var funcPtr = BurstCompiler.CompileFunctionPointer<Pointers.StreamWriteDelegate>(Pointers.StreamWrite);
Measure.Method(() => { funcPtr.Invoke(ref stream, numElements); })
.WarmupCount(100)
.MeasurementCount(1000)
.Run();
stream.Dispose();
}
}
}