U# vs C#
U# is noticeably slower than regular C#, to benchmark it I decided to execute two scripts in U# and C#, one calculates the n-th element in the Fibonacci series, the second one generates a maze.
To make the tests a bit fairer, I disable the C# compiler optimization, since the U# compiler does not optimize your scripts
Recursive functions
For this test I executed a script that finds the nth element in the Fibonacci series, the Fibonacci method looks like this
[RecursiveMethod]
public int FibonacciRecursive(int n)
{
if (n <= 1)
return n;
else
return FibonacciRecursive(n - 1) + FibonacciRecursive(n - 2);
}
Since FibonacciRecursive
is a recursive function, the [RecursiveMethod]
attribute need to be added.
This is really a horrible way to calculate the nth element in the Fibonacci serie because certain method calls get called multiple times, and the number of method call rises very quicklyl :
Fibonacci(1)
calls the Fibonacci method 1 timeFibonacci(2)
calls the Fibonacci method 3 timesFibonacci(10)
calls the Fibonacci method 177 timesFibonacci(22)
calls the Fibonacci method 57313 time
So I felt like this test is an amazing way to determine how well U# performs this task.