serfreeman1337 - Аренда игровых серверов

Comparing get player list methods

Sometimes you need to get certain player indexes. The right way to do it is use of get_players native. But the most mistakes are made by beginner scripters is way of loop through player indexes and filter them by AMXX natives. This way is fully wrong and that is why.

Its all about plugin optimization. The main rule of optimization is:

Less natives - more efficient.

Lets take look of loop method:

Now lets know how many calls was made and how much time it took. We use AMXX special build for plugins profiling - AMXX 1.8.2-rev24 profiler

Code take 0.000011 seconds to execute. About 33 calls happens.

Lets compare it with get_players. Following code:

Profile result:

This method took 0.000002 seconds to execute. Accessing functions AMXX was only once.

For better understanding, lets do stress-test. Execute this code block 1000 times. Following code:

Profile result:

get_players - 0.000320. loop - 0.009689. A significant difference, isn't it? get_players is faster than loop in 30 times. 30 times! Is much enough to stop use of loop method in your plugins :)

  • Вася says:

    Попробуйте прогнать вот эти оптимизированные варианты. Даже с оптимизацией loop выигрывает в 3 раза. На моем процессоре результат 10 секунд loop и 34 секунды get_players.

Leave a Reply