23.08.2016, 20:21
Quote:
That's not the best solution, it isn't recommended to use sscanf when you're handling a single parameter. To solve the OP issue, you need to start to address the variable as an integer. (using strval())
|
Do a small test, you'd notice that sscanf (the plugin, not the pawn version) is actually faster than strval.
Also, in that situation, you'd have to use isnull, which also slows it down.
Which means sscanf is the better option:
PHP код:
new val1, val2, times = 10000000, str[] = "543";
new tick1 = GetTickCount();
for (new i = 0; i < times; i++)
{
if (isnull(str)) continue;
val1 = strval(str);
}
new tick2 = GetTickCount();
for (new i = 0; i < times; i++)
{
if (sscanf(str, "i", val2)) continue;
}
new tick3 = GetTickCount();
printf("strval: %i\nsscanf: %i", tick2 - tick1, tick3 - tick2);
printf("val1: %i\nval2: %i", val1, val2);
-------- Results:
strval: 1954
sscanf: 1554
strval: 1935
sscanf: 1561
strval: 1930
sscanf: 1543