22.07.2011, 13:20
(
Последний раз редактировалось Incognito; 29.07.2011 в 07:11.
)
Quote:
****** and other experts - any idea why the c++ version is slower? i managed to track down to invoke->callNative function.. so whenever i call sa-mp natives via invoke that's significantly slower than doing it in pawn (pure math functions work faster tho), so this is unacceptable to me.. if calling samp natives via invoke makes the whole thing slower than in pawn, i should just stop this project - there is no other option.
|
Anyway, I've done some profiling and Zeex's gamemode SDK is clearly the winner here.
Код:
void methodOne() { boost::chrono::high_resolution_clock::time_point begin = boost::chrono::high_resolution_clock::now(); for (int i = 0; i < 1000000; ++i) { invoke->callNative(&PAWN::GetPlayerPos, playerid, &x, &y, &z); } boost::chrono::duration<double, boost::milli> end = boost::chrono::high_resolution_clock::now() - begin; logprintf("methodOne(): %g", end.count()); }
Код:
void methodTwo() { boost::chrono::high_resolution_clock::time_point begin = boost::chrono::high_resolution_clock::now(); for (int i = 0; i < 1000000; ++i) { samp::GetPlayerPos(playerid, x, y, z); } boost::chrono::duration<double, boost::milli> end = boost::chrono::high_resolution_clock::now() - begin; logprintf("methodTwo(): %g", end.count()); }
Код:
[07:20:48] methodOne(): 305.934 [07:20:48] methodTwo(): 22.3173
Edit: I also don't mean to say that callNative is incredibly slow. In the test above, each call took about 300 nanoseconds (or 300 billionths of a second) to complete. That's still pretty fast, even if a PAWN implementation is a bit faster.