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 :
Benchmark1
callsFibonacciRecursive
in the same scriptBenchmark2
callsFibonacciRecursive
from a separate script
B1 : 236.120 ms
B2 : 305.513ms (1.29 times slower)
So yes, calling a method from a separate script affects the performance, but is it really worth it to write everything inside a single script file? Personally I don't like reading scripts that are 5000+ lines long