View Single Post
seriousspot
BANNED
Join Date: Mar 2013
Location: Lithuania / Norway
Old 08-19-2013 , 13:35   Re: pev_frags crashing after update, either my code is bad
Reply With Quote #15

Quote:
Originally Posted by Black Rose View Post
Each method in a loop of 10 000 000 times.
Code:
#include <amxmodx> #include <fakemeta> #include <cstrike> public plugin_init() {     register_plugin("Test Plugin 7", "", "");         set_task(5.0, "test1") } #define LOOPS   10000000 public test1() {         new MaxClients = global_get(glb_maxClients);     new Timer = get_systime();         for ( new c = 0 ; c < LOOPS ; c++ ) {         new Players[32], PlayersNum;         get_players(Players, PlayersNum, "ace", "TERRORIST");         for ( new i = 0 ; i <= PlayersNum ; i++ ) { }     }         server_print("Method 1: %d", get_systime() - Timer);     Timer = get_systime();         for ( new c = 0 ; c < LOOPS ; c++ ) {         new team[32];         for ( new i = 1 ; i <= MaxClients ; i++ ) {             if ( is_user_alive(i) && ! is_user_bot(i) && get_user_team(i, team, charsmax(team)) == 1 ) { }         }     }         server_print("Method 2: %d", get_systime() - Timer);     Timer = get_systime();             for ( new c = 0 ; c < LOOPS ; c++ ) {         for ( new i = 1 ; i <= MaxClients ; i++ ) {             if ( is_user_alive(i) && ! is_user_bot(i) && cs_get_user_team(i) == CS_TEAM_T ) { }         }     }         server_print("Method 3: %d", get_systime() - Timer); }

Code:
Method 1: 2
Method 2: 19
Method 3: 18
Bare in mind though that this was a server with no players.
Get players will still use the team name to retrieve a team ID before looping players.
It's still faster than both other methods, which are only calling is_user_alive() since it will return false. Maybe the time is just being spent in the actual looping than just calling natives.

For those of you that get false results with the team flag, at which point is the function called? Event, command, forward et.c.
dumb comparision also i am using cached values, ands theres only 32-33 loops depends on get_maxplayers
seriousspot is offline