暫無描述
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.

SumNumberJob.cs 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using System;
  2. using System.Runtime.CompilerServices;
  3. using Unity.Collections;
  4. using Unity.Jobs;
  5. [assembly: InternalsVisibleTo("Burst.Benchmarks")]
  6. namespace UnityBenchShared
  7. {
  8. internal struct SumNumbersTest : IJob, IDisposable
  9. {
  10. public const int Count = 10000000;
  11. public NativeArray<float> output;
  12. [ReadOnly]
  13. public NativeArray<float> a;
  14. [ReadOnly]
  15. public NativeArray<float> b;
  16. public void Execute()
  17. {
  18. for (int i = 0; i < Count; ++i)
  19. {
  20. output[i] = a[i] + b[i];
  21. }
  22. }
  23. public struct Provider : IArgumentProvider
  24. {
  25. public object Value
  26. {
  27. get
  28. {
  29. var job = new SumNumbersTest();
  30. job.output = new NativeArray<float>(Count, Allocator.Persistent);
  31. job.a = new NativeArray<float>(Count, Allocator.Persistent);
  32. job.b = new NativeArray<float>(Count, Allocator.Persistent);
  33. for (int i = 0; i < Count; i++)
  34. {
  35. job.a[i] = i;
  36. }
  37. return job;
  38. }
  39. }
  40. }
  41. public void Dispose()
  42. {
  43. output.Dispose();
  44. a.Dispose();
  45. b.Dispose();
  46. }
  47. }
  48. }