The "ref" keyword
U# now supports the "ref" keyword, which is really cool!
But does using it affect the performance?
private void FunctionRef(ref int a)
{
a = 1;
}
private int FunctionRet(ref int a)
{
return 1;
}
public override void Benchmark1()
{
for (int i = 0; i < 50000; i++)
{
int a = 0;
FunctionRef(ref a);
}
}
public override void Benchmark2()
{
for (int i = 0; i < 50000; i++)
{
int a = 0;
a = FunctionRet();
}
}
B1 : 14.859 msĀ
B2 : 14.171 ms (1.04 times slower)
Good news! The difference is really negligible, you can safely use "ref" without worrying about performance impacts