Calling methods from a separate script

Let's say you have script A that accesses a method from script B.

Would it be more performant to merge script A and B together? Let's see!


public Fibonacci FibonacciInstance;

[RecursiveMethod]
private int FibonacciRecursive(int n)
{
	if (n <= 0)
		return 0;
	else
		return 1 + FibonacciRecursive(n - 1);
}

public override void Benchmark1()
{
	for (int i = 0; i < 10000; i++)
	{
		FibonacciRecursive(2);
	}
}

public override void Benchmark2()
{
	for (int i = 0; i < 10000; i++)
	{
		FibonacciInstance.FibonacciRecursive(2);
	}
}

Both methods do the same thing :

B1 : 236.120 ms 
B2 : 305.513ms (1.29 times slower)

So yes, calling a method from a separate script affects the performance.


Revision #2
Created 15 February 2023 20:35:59 by MyroP
Updated 16 February 2023 20:54:13 by MyroP