Raised This Month: $344 Target: $400
 86%   Almost there!

[INFO] Bitsums and Operators


Post New Thread Reply   
 
Thread Tools Display Modes
joaquimandrade
Veteran Member
Join Date: Dec 2008
Location: Portugal
Old 04-20-2009 , 04:41   Re: [INFO] Bitsums and Operators
Reply With Quote #21

Quote:
Originally Posted by Empowers View Post
This A result from your code, I profiled it.. Read more carefully my post ;)
... Guess where there is a continue and where there are 10 function calls.
__________________
joaquimandrade is offline
Empowers
BANNED
Join Date: Feb 2009
Location: Ukraine
Old 04-20-2009 , 04:44   Re: [INFO] Bitsums and Operators
Reply With Quote #22

Quote:
Originally Posted by joaquimandrade View Post
... Guess where there is a continue and where there are 10 function calls.
Quote:
Originally Posted by Empowers View Post
I profiled your code here is the result:
Code:
date: Sun Apr 19 19:21:59 2009 map: de_dust
type |                             name |      calls | time / min / max
-------------------------------------------------------------------
   n |                       server_cmd |          1 | 0.000005 / 0.000005 / 0.000005
   p |                       plugin_cfg |          1 | 0.011147 / 0.011147 / 0.011147
   f |                            Index |      20000 | 0.006789 / 0.000000 / 0.000292
   f |                              Bit |      20000 | 0.005406 / 0.000000 / 0.000011
0 natives, 2 public callbacks, 1 function calls were not executed.
Empowers is offline
Send a message via ICQ to Empowers
joaquimandrade
Veteran Member
Join Date: Dec 2008
Location: Portugal
Old 04-20-2009 , 04:44   Re: [INFO] Bitsums and Operators
Reply With Quote #23

Quote:
Originally Posted by Empowers View Post
Wow thx for Great TUT!


Profiled:

Code:
date: Sun Apr 19 15:20:28 2009 map: de_dust
type |                             name |      calls | time / min / max
-------------------------------------------------------------------
   n |                   register_clcmd |          2 | 0.000019 / 0.000004 / 0.000015
   p |                       array_test |         10 | 0.064196 / 0.006202 / 0.006642
   p |                      bitsum_test |         10 | 0.029594 / 0.002811 / 0.003570
   p |                      plugin_init |          1 | 0.000002 / 0.000002 / 0.000002
0 natives, 0 public callbacks, 3 function calls were not executed.
Tested on this code:
PHP Code:
#include <amxmodx>

new array[33]
new 
bitsum

public plugin_init() 
{
    array[
32] = false
        
    bitsum 
&=  ~(1<<32
    
    
register_clcmd("array","array_test")
    
register_clcmd("bitsum","bitsum_test")
}

public 
bitsum_test()
{
    for(new 
i;i<=1_000_000;i++)
        if(
bitsum & (1<<32))
            continue;
}

public 
array_test()
{
    for(new 
i;i<=1_000_000;i++)
        if(array[
32])
            continue;

Now I'm thinking should I swap arrays with bitsums in my plugins code. It would use less memory, but it will be harder to understand the code.
__________________
joaquimandrade is offline
Empowers
BANNED
Join Date: Feb 2009
Location: Ukraine
Old 04-20-2009 , 04:52   Re: [INFO] Bitsums and Operators
Reply With Quote #24

Ok forget it man.. I can't talk with u
Empowers is offline
Send a message via ICQ to Empowers
joaquimandrade
Veteran Member
Join Date: Dec 2008
Location: Portugal
Old 04-20-2009 , 04:53   Re: [INFO] Bitsums and Operators
Reply With Quote #25

Quote:
Originally Posted by Empowers View Post
Ok forget it man.. I can't talk with u
Of course you can. But you need to
Quote:
Read more carefully my post ;)
__________________
joaquimandrade is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 04-20-2009 , 07:10   Re: [INFO] Bitsums and Operators
Reply With Quote #26

Ahem, andrade.
"continue" is never called because the if() statement never returns true.

Code:
    array[32] = false             bitsum &=  ~(1<<32)
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
SchlumPF*
Veteran Member
Join Date: Mar 2007
Old 04-20-2009 , 07:43   Re: [INFO] Bitsums and Operators
Reply With Quote #27

nice idea but in fact this is a very trivial optimization... 1byte vs 132byte... 1byte = ~0.000000001gb, nearly every computer has 1gb ram :/ anyway, this would have been a great idea when computers had ~8mb ram
this topic would still make sense if you change its focus from ram optimizations to a general tutorial for bitsums.
__________________
SchlumPF* is offline
Send a message via ICQ to SchlumPF*
Empowers
BANNED
Join Date: Feb 2009
Location: Ukraine
Old 04-20-2009 , 08:02   Re: [INFO] Bitsums and Operators
Reply With Quote #28

Quote:
Originally Posted by SchlumPF* View Post
nice idea but in fact this is a very trivial optimization... 1byte vs 132byte... 1byte = ~0.000000001gb, nearly every computer has 1gb ram :/ anyway, this would have been a great idea when computers had ~8mb ram
But if it is used in EntityThink, addToFullPack hooks. Or somethink that is called very often? I think I would be a good optimization?
Empowers is offline
Send a message via ICQ to Empowers
SchlumPF*
Veteran Member
Join Date: Mar 2007
Old 04-20-2009 , 08:49   Re: [INFO] Bitsums and Operators
Reply With Quote #29

Quote:
Originally Posted by Empowers View Post
But if it is used in EntityThink, addToFullPack hooks. Or somethink that is called very often? I think I would be a good optimization?
it would be a very small optimization, yes.
__________________
SchlumPF* is offline
Send a message via ICQ to SchlumPF*
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 04-20-2009 , 11:11   Re: [INFO] Bitsums and Operators
Reply With Quote #30

Quote:
Originally Posted by Empowers View Post
PHP Code:
#define AddFlag(%1,%2)       ( %1 |= ( 1 << (%2-1) ) )
#define RemoveFlag(%1,%2)    ( %1 &= ~( 1 << (%2-1) ) )
#define CheckFlag(%1,%2)     ( %1 & ( 1 << (%2-1) ) ) 
but is this better?
PHP Code:
#define AddFlag(%1,%2)        ( %1 |= ( 1 << (%2 % 32) ) )
#define RemoveFlag(%1,%2)     ( %1 &= ~( 1 << (%2 % 32) ) )
#define CheckFlag(%1,%2)      ( %1 & ( 1 << (%2 % 32) ) ) 
They both do the same thing to prevent a bit-shift of 32 bits. There is no performance change or any other benefit for using either. For a shift of 1-32, -1 will shift 0-31. Using % for a shift of 1-32, it will shift 1-31 normally but when 32 is passed it will shift 0.

The -1 method:
Code:
AddFlag(_,1) = 1 << 0
AddFlag(_,31) = 1 << 30
AddFlag(_,32) = 1 << 31
The modulus method (%):

Code:
AddFlag(_,1) = 1 << 1
AddFlag(_,31) = 1 << 31
AddFlag(_,32) = 1 << 0
__________________

Last edited by Bugsy; 04-20-2009 at 11:51.
Bugsy is offline
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 21:49.


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