Raised This Month: $32 Target: $400
 8% 

[TUT] Modules and efficient scripting


Post New Thread Reply   
 
Thread Tools Display Modes
joaquimandrade
Veteran Member
Join Date: Dec 2008
Location: Portugal
Old 03-29-2009 , 17:40   Re: [TUT] Modules and efficient scripting
Reply With Quote #31

Quote:
Originally Posted by SchlumPF* View Post
never used pev_valid(id) == 2 but i guess it is not really needed.
if you set some ents pdata you should already know whether it has pdata. but it may be usefull if you loop through different kinds of ents (classnames)
I know what it is but also never needed to check if "equals 2".

Quote:
Originally Posted by SchlumPF* View Post
a new question which came to my mind
is there any difference in
client_preThink( plr ) and register_forward( FM_PlayerPreThink, "fwdPlayerPreThink" ) ?
I guess that there isn't any difference.
__________________

Last edited by joaquimandrade; 03-29-2009 at 17:46.
joaquimandrade is offline
SchlumPF*
Veteran Member
Join Date: Mar 2007
Old 03-29-2009 , 19:11   Re: [TUT] Modules and efficient scripting
Reply With Quote #32

i just answered your question, i think that the function itself is just usefull if you need to loop through different types of ents.
__________________

Last edited by SchlumPF*; 03-30-2009 at 09:02.
SchlumPF* is offline
Send a message via ICQ to SchlumPF*
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 03-30-2009 , 08:24   Re: [TUT] Modules and efficient scripting
Reply With Quote #33

I'm not sure but I'd guess that client_PreThink() becomes much faster once there's more than one plugin using it, since it's a multiforward.
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
hleV
Veteran Member
Join Date: Mar 2007
Location: Lithuania
Old 03-30-2009 , 09:17   Re: [TUT] Modules and efficient scripting
Reply With Quote #34

You should do like 3-5 tests to compare each FM's & Engine's function type speed.

Like get_pdata_int() 3-5 times & Engine's way that does the same 3-5 times. That would make it clear for everyone which way is better.
__________________
hleV is offline
xPaw
Retired AMX Mod X Moderator
Join Date: Jul 2008
Old 03-30-2009 , 09:41   Re: [TUT] Modules and efficient scripting
Reply With Quote #35

Engine/Fakemeta/HamSandwich PreThink test.

Code:
date: Mon Mar 30 16:38:56 2009 map: de_dust2
type |                             name |      calls | time / min / max
-------------------------------------------------------------------
   n |                  register_plugin |          1 | 0.000004 / 0.000004 / 0.000004
   n |                 register_forward |          1 | 0.000009 / 0.000009 / 0.000009
   n |                      RegisterHam |          1 | 0.000091 / 0.000091 / 0.000091
   n |                         set_task |          1 | 0.000006 / 0.000006 / 0.000006
   n |                          log_amx |          3 | 0.007320 / 0.001663 / 0.003362
   n |                       server_cmd |          1 | 0.000014 / 0.000014 / 0.000014
   p |                  client_PreThink |       1688 | 0.004612 / 0.000001 / 0.000422
   p |              fwdFMPlayerPreThink |       1688 | 0.002990 / 0.000001 / 0.000536
   p |             fwdHamPlayerPreThink |       1688 | 0.002635 / 0.000001 / 0.000255
   p |                 fnShutDownServer |          1 | 0.000013 / 0.000013 / 0.000013
   p |                      plugin_init |          1 | 0.000006 / 0.000006 / 0.000006
6 natives, 1 public callbacks, 6 function calls were not executed.
Attached Files
File Type: sma Get Plugin or Get Source (PreThinkPower.sma - 663 views - 790 Bytes)
__________________

Last edited by xPaw; 03-30-2009 at 09:53.
xPaw is offline
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 03-30-2009 , 09:49   Re: [TUT] Modules and efficient scripting
Reply With Quote #36

Quote:
Originally Posted by xPaw View Post
Engine/Fakemeta/HamSandwich PreThink test.

Code:
date: Mon Mar 30 16:38:56 2009 map: de_dust2
type |                             name |      calls | time / min / max
-------------------------------------------------------------------
   n |                  register_plugin |          1 | 0.000004 / 0.000004 / 0.000004
   n |                 register_forward |          1 | 0.000009 / 0.000009 / 0.000009
   n |                      RegisterHam |          1 | 0.000091 / 0.000091 / 0.000091
   n |                         set_task |          1 | 0.000006 / 0.000006 / 0.000006
   n |                          log_amx |          3 | 0.007320 / 0.001663 / 0.003362
   n |                       server_cmd |          1 | 0.000014 / 0.000014 / 0.000014
   p |                  client_PreThink |       1688 | 0.004612 / 0.000001 / 0.000422
   p |              fwdFMPlayerPreThink |       1688 | 0.002990 / 0.000001 / 0.000536
   p |             fwdHamPlayerPreThink |       1688 | 0.002635 / 0.000001 / 0.000255
   p |                 fnShutDownServer |          1 | 0.000013 / 0.000013 / 0.000013
   p |                      plugin_init |          1 | 0.000006 / 0.000006 / 0.000006
6 natives, 1 public callbacks, 6 function calls were not executed.
I don't think that's a fair test since you're basically benchmarking CreateOneForward against CreateMultiForward. If you create a bunch of plugins which use client_PreThink, it will likely be faster.

The other problem is that you're not benchmarking how long it takes for the modules to find and call each function. You can't really profile forwards. As far as I know, it can only benchmark stuff done in the VM layer.

A good test would be to benchmark how long it takes between PreThink and PostThink. You could probably draw a more accurate conclusion from that.
__________________

Last edited by Hawk552; 03-30-2009 at 09:51.
Hawk552 is offline
Send a message via AIM to Hawk552
joaquimandrade
Veteran Member
Join Date: Dec 2008
Location: Portugal
Old 03-30-2009 , 10:34   Re: [TUT] Modules and efficient scripting
Reply With Quote #37

I have two questions:

How can increment a variable inside a forward be less or more expensive depending on which forward?

What is the point of profiling forwards?

Anyway, i've made more neutral profiling for you. Here it goes:
Attached Files
File Type: txt profile.txt (1.3 KB, 198 views)
File Type: sma Get Plugin or Get Source (eng.sma - 568 views - 314 Bytes)
File Type: sma Get Plugin or Get Source (fm.sma - 632 views - 373 Bytes)
__________________

Last edited by joaquimandrade; 03-30-2009 at 10:51.
joaquimandrade is offline
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 03-30-2009 , 10:47   Re: [TUT] Modules and efficient scripting
Reply With Quote #38

Quote:
Originally Posted by joaquimandrade View Post
How can increment a variable inside a forward be less or more expensive depending on which forward?
As far as I know, it's profiling how long it actually takes for it to execute the function from front to back. I don't think it includes how long it takes to actually find it, though.

Quote:
Originally Posted by joaquimandrade View Post
What is the point of profiling forwards?
Well, we're trying to see whether FakeMeta's one forwards are faster than Engine's multi forwards. I think it's a good idea to benchmark these against each other.
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
joaquimandrade
Veteran Member
Join Date: Dec 2008
Location: Portugal
Old 03-30-2009 , 10:52   Re: [TUT] Modules and efficient scripting
Reply With Quote #39

Quote:
Originally Posted by Hawk552 View Post
As far as I know, it's profiling how long it actually takes for it to execute the function from front to back. I don't think it includes how long it takes to actually find it, though.



Well, we're trying to see whether FakeMeta's one forwards are faster than Engine's multi forwards. I think it's a good idea to benchmark these against each other.
What "a forward being faster than other" means?
__________________

Last edited by joaquimandrade; 03-30-2009 at 11:01.
joaquimandrade is offline
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 03-30-2009 , 11:02   Re: [TUT] Modules and efficient scripting
Reply With Quote #40

Quote:
Originally Posted by joaquimandrade View Post
What means "a forward being faster than other"?
If it takes less time for all of the equivalent functions to be found and then executed from front to back with identical code inside them, then you can consider that forward faster than the one you're comparing it to. Basically, what I'm saying is this:

As far as I know, AMXX keeps a "lookup table" of all public functions in each active plugin. I think it would be faster to go through this and look for "client_PreThink" in each plugin than it would be to navigate through the registered forwards in FakeMeta. I could be wrong, though; one reason being that multiforwards have to scan through each plugin and each function in them, which I would assume becomes more and more trivial as FM_PlayerPreThink gets registered more times. FM_PlayerPreThink, however, has to execute a separate forward for each plugin registering it.

I don't know the internal workings of AMXX's forward handling well enough to really say with total certainty which would be faster. What I've posted is just a guess. It's also hard to benchmark them against each other. As I said before, a better benchmark may be to check how long it takes between PreThink and PostThink in each module, assuming that each forward is executed in the same order each time. This would include how long it takes to look up the PostThink function. The profiler, however, isn't capable of checking times between functions and can only track how long it takes for a function to run to completion.

Basically, I think we'd need a developer to tell us. There's no real way of benchmarking them against each other properly.
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
Reply


Thread Tools
Display Modes

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 19:01.


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