This site is a testing version, but all data is shared with the live forum.


Raised This Month: $ Target: $400
 0% 

which on is faster?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
killergirl
Senior Member
Join Date: Jul 2010
Old 02-13-2012 , 18:04   which on is faster?
Reply With Quote #1

Because get_pcvar_num() is a function, everytime when another function (public) is called the function get_pcvar_num() is working. I know, I read somewhere get_pcvar_num() is ~5x faster than get_cvar_num(), but what if I put into a global variable? It's more faster?

#1 -> called each time if function print() is called
PHP Code:
new g_cvar

public plugin_init(){
   
///
   
g_cvar register_cvar("amx_cvar""1")
}

public print(){
   
client_print(0print_chat"--> THIS ONE ! %d"get_pcvar_num(g_cvar) )

#2 -> once called in plugin_cfg()
PHP Code:
new g_cvarg_newCvar

public plugin_init(){
   
///
   
g_cvar register_cvar("amx_cvar""1")
}

public 
plugin_cfg(){
   
g_newCvar get_pcvar_num(g_cvar)
}

public print(){
   
/* Can't use:
   client_print(0, print_chat, "--> %d", g_cvar)
   */
   
client_print(0print_chat"--> %d"g_newCvar)

I know it's a disadvantage for people who want's to modify their cvars while server is running.

I made this topic beacause I'm trying to find the fastest way, because one of the function is called everytime when a player get damaged.
killergirl is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 02-13-2012 , 18:10   Re: which on is faster?
Reply With Quote #2

The one without the native is the fastest (global variable). If you don't want the variable changed mid-game then use this method.
__________________
fysiks is offline
Doc-Holiday
AlliedModders Donor
Join Date: Jul 2007
Old 02-13-2012 , 19:56  
Reply With Quote #3

The variables. Might be faster but is it noticable prolly not... And most people like to be able to alter their cvars in the middle of the game. You can create a concmd though that can change the. Cvar and reassign the new value to the global var
Doc-Holiday is offline
bibu
Veteran Member
Join Date: Sep 2010
Old 02-14-2012 , 06:48   Re: which on is faster?
Reply With Quote #4

Or you could cache the cvar at new rounds.
__________________
Selling tons of my own private works.
Accepting paid work for clans and communities.
Don't hesitate to contact me.
bibu is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 02-14-2012 , 07:39   Re: which on is faster?
Reply With Quote #5

Or using Cvar Utilities.
__________________
Arkshine is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 02:14.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode