Beispiel #1
0
    private (long mainTicks, long jobTicks) MainThreadPerformanceTest(AnimationCurve ac, int iterationCount)
    {
        System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();

        var jac = new NativeAnimationCurve(ac, Allocator.Temp);

        float[] evaluated = new float[iterationCount];

        sw.Start();
        for (int i = 0; i < evaluated.Length; i++)
        {
            evaluated[i] = jac.Evaluate(i / (float)iterationCount);
        }
        sw.Stop();
        var jobTicks = sw.ElapsedTicks;

        sw.Reset();

        sw.Start();
        for (int i = 0; i < evaluated.Length; i++)
        {
            evaluated[i] = ac.Evaluate(i / (float)iterationCount);
        }
        sw.Stop();
        var mainTicks = sw.ElapsedTicks;


        jac.Dispose();

        return(mainTicks, jobTicks);
    }
Beispiel #2
0
    private (long mainTicks, long jobTicks) TestEvaluate(AnimationCurve ac, int iterationCount)
    {
        System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();

        var jac = new NativeAnimationCurve(ac, Allocator.TempJob);

        NativeArray <float> evaluated    = new NativeArray <float>(iterationCount, Allocator.TempJob);
        NativeArray <float> jobEvaluated = new NativeArray <float>(iterationCount, Allocator.TempJob);
        var job = new CurveEvaluationJob
        {
            evaluated         = jobEvaluated,
            jobAnimationCurve = jac
        }.Schedule(iterationCount, testEvaluateBatchCount, default(JobHandle));

        sw.Start();
        for (int i = 0; i < evaluated.Length; i++)
        {
            evaluated[i] = ac.Evaluate(i / (float)iterationCount);
        }
        sw.Stop();
        var mainTicks = sw.ElapsedTicks;

        sw.Reset();

        sw.Start();
        job.Complete();
        sw.Stop();
        var jobTicks = sw.ElapsedTicks;

        for (int i = 0; i < evaluated.Length; i++)
        {
            //Within 0.00001f, it is a bit inaccurate.
            Assert.That(evaluated[i], Is.EqualTo(jobEvaluated[i]).Within(0.0001f),
                        $"At index {i} (time {i / (float)iterationCount}) there is a difference of Unity {evaluated[i]} and Job {jobEvaluated[i]} ({evaluated[i] - jobEvaluated[i]})");
        }

        evaluated.Dispose();
        jobEvaluated.Dispose();
        jac.Dispose();

        return(mainTicks, jobTicks);
    }