Skip to content

Benchmark Vector Multiplication

Aprius edited this page Nov 1, 2024 · 1 revision

Vector Multiplication

Directly Mul

Vector3[] input = new Vector3[1000];

... // init vector input to test

Vector3[] DefaultVectorMultiplication()
{
    Vector3[] results = new Vector3[1000];

    for (int i = 0; i < 1000; i++)
    {
        results[i] = input[i] * 5f;
    }

    return results;
}

Custom Mul

Vector3[] input = new Vector3[1000];

... // init vector input to test

Vector3[] DefaultVectorMultiplication()
{
    Vector3[] results = new Vector3[1000];

    for (int i = 0; i < 1000; i++)
    {
        Vector3 curr = input[i];
        Vector3 result;
        result.x = curr.x * 5f;
        result.y = curr.y * 5f;
        result.z = curr.z * 5f;
        results[i] = result;
    }

    return results;
}

Result

image

Clone this wiki locally