4
I’m doing some tests with some C# codes and during an analysis I realized that some high-peak problems happen when integer value conversions occur to string, in the vast majority the conversion happens so: classe.valor.ToString("0.0")
is there any way to improve this type of conversion? Using string.Format("{0:0.00}", classe.valor)
the peak got even higher reducing the performance of the application. It would have some alternative?
These conversions happen within a continuous function, which is updated every frame.
Not to post the entire code here values come from several classes so I will post only a few snippets of one of the classes, so I can apply to the others:
distancia.text = string.Concat(string.Format("{0:0.00}", distance.metros), " m");
if (contar)
{
i -= Time.deltaTime;
timeCount.text = i.ToString("0").Replace("0","Go");
if (i < 0)
{
contar = false;
}
}
checkpoint.text = string.Concat("Distance: ", string.Format("{0:0.00}", distance.metros), " m");
if (manager.count)
{
var valor = int.Parse(rota.metros.ToString("00"));
_menuManager.ShowMenu(Menu);
endPoints.text = string.Concat("distance: ", string.Format("{0:0.00}", rotaMaior.metros), " m");
}
It’s hard to point out anything. Post the rest of the code, where exactly there is the peak, as you measured, anyway, give more details so we can help.
– Maniero