We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BurstCompile(OptimizeFor = OptimizeFor.Performance)] public unsafe static class BurstLinq { public static int Sum(List<int> source) { var span = SpanHelper.AsSpan(source); fixed (int* ptr = span) { SumCore(ptr, source.Count, out var result); return result; } } [BurstCompile(FloatMode = FloatMode.Fast)] internal static void SumCore(int* ptr, [AssumeRange(1, int.MaxValue)] int length, out int result) { var sum = default(int); for (var i = 0; i < length; i++) sum += ptr[i]; result = sum; } } public unsafe static class NoBurstLinq { public static int Sum(List<int> source) { var span = SpanHelper.AsSpan(source); fixed (int* ptr = span) { SumCore(ptr, source.Count, out var result); return result; } } internal static void SumCore(int* ptr, [AssumeRange(1, int.MaxValue)] int length, out int result) { var sum = default(int); for (var i = 0; i < length; i++) sum += ptr[i]; result = sum; } } public class TestBehaviour : MonoBehaviour { private List<int> ints; private int = 1000000; void Start() { ints = Enumerable.Range(0,1000).ToList(); } void Update() { var localValue = 0; Profiler.BeginSample("Linq"); for (var i = 0; i < length; i++) { localValue += ints.Sum(); } Profiler.EndSample(); Profiler.BeginSample("NoBurstLinq"); for (var i = 0; i < length; i++) { localValue += NoBurstLinq.Sum(ints); } Profiler.EndSample(); Profiler.BeginSample("BurstLinq"); for (var i = 0; i < length; i++) { localValue += BurstLinq.Sum(ints); } Profiler.EndSample(); } }
The text was updated successfully, but these errors were encountered:
Interesting result. I will need to look into this in more detail.
Sorry, something went wrong.
Perhaps this may have something to do with it. https://issuetracker-mig.prd.it.unity3d.com/issues/burst-compiled-job-is-completed-few-times-slower-than-il2cpp
These numbers look weird. Given that localValue isn't stored anywhere, perhaps IL2CPP optimized the computation away completely?
localValue
No branches or pull requests
[Mono Build] is better than Non BurstCompile
but [IL2cpp Build] is not fast than BurstCompile
TestCode
The text was updated successfully, but these errors were encountered: