14.01.2017, 11:14
Quote:
I would very much like to see that benchmark because that seems a lot. I use the operators purely for aesthetic purposes and readability. Especially in longer calculations where the oversight would be easily lost due to the overabundance of brackets. That old GetDistanceBetweenPlayers function that people keep copying is a prime example.
|
PHP Code:
#define BENCHMARK(%0,%1,%2); \
{\
new start = GetTickCount();\
for(new count = 0; count < %1; count++)\
{\
%0;\
}\
printf("%s: %dms in %d iterations", %2, GetTickCount() - start, %1);\
}
#define TEST_ITERATIONS 10000000
BENCHMARK((1000.0 - 150.0) / 7.5, TEST_ITERATIONS, "operators - and /");
BENCHMARK(floatdiv(floatsub(1000.0, 150.0), 7.5), TEST_ITERATIONS, "natives floatsub and floatdiv");
And yeah, i just realized how retarded that was, that i just generalized that the natives are faster, even though i didn't test them all and i just tested a specific case. in this case for example it is faster, but there were other cases where it was equally fast.
Maybe i am just too dumb to do benchmarking, that might be the case
Sorry for doing the thinking after the doing ...
But anyways, if the natives aren't faster, why would they exist, i have asked myself that.