Raised This Month: $51 Target: $400
 12% 

Solved need help in optimization [weird coding]


Post New Thread Reply   
 
Thread Tools Display Modes
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 01-22-2022 , 07:13   Re: need help in optimization [weird coding]
Reply With Quote #11

Quote:
Originally Posted by Natsheh View Post
PHP Code:
#define MAX_NAME_LENGTH 32
new szName[MAX_NAME_LENGTH 2], len;
get_user_name(idszNameMAX_NAME_LENGTH-1);
szName[(len=strlen(szName))] = ' ';
szName[len+1] = 0
At some point you need to question whether readability or 0.0000000001 second faster execution is more important.
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 01-22-2022 , 07:15   Re: need help in optimization [weird coding]
Reply With Quote #12

I agree with OciXCrom, I don't see the point in not using formatex to add a space.
__________________
HamletEagle is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 01-22-2022 , 07:28   Re: need help in optimization [weird coding]
Reply With Quote #13

yeah, you're right for personal use i recommend using anything which might increase the speed.
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !

Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 01-22-2022 , 09:55   Re: need help in optimization [weird coding]
Reply With Quote #14

Quote:
Originally Posted by Natsheh View Post
yeah, you're right for personal use i recommend using anything which might increase the speed.
But you are increasing the speed of appending a space to the end of a potentially 32 characters long string... which does literally nothing. If your string had millions of characters it would make sense to be concerned about it.
__________________

Last edited by HamletEagle; 01-22-2022 at 09:56.
HamletEagle is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 01-22-2022 , 14:43   Re: need help in optimization [weird coding]
Reply With Quote #15

Quote:
Originally Posted by kww View Post
What do you mean? I know that. I wrote I need NOT only the name but a space after it too
Code:
formatex(szTemp, charsmax(szTemp), "%s ", szName)
                                      ^
If you know how to do it another way then please tell me

Sure, I can do this to add a space but what's the difference then:
Code:
case NAME_ONLY:
{
	get_user_name(iSender, szTemp, charsmax(szTemp))
	add(szTemp, charsmax(szTemp), " ")
}
I thought you were asking a question if you needed to add a space in the format string to make it work. Your sentence didn't end with any punctuation so I misinterpreted your post.
__________________

Last edited by fysiks; 01-22-2022 at 14:46.
fysiks is offline
Supremache
Veteran Member
Join Date: Sep 2019
Location: Egypt
Old 01-26-2022 , 03:54   Re: need help in optimization [weird coding]
Reply With Quote #16

PHP Code:

#if !defined MAX_TEXT_LENGTH
const MAX_TEXT_LENGTH 192
#endif

enum _:eNotifyType {
    
ID_ONLY 1,
    
NAME_ONLY
}

enum _:ePrintType {
    
PRINT_CHAT 1,
    
PRINT_CONSOLE
}
// Put the player id first thing when creating the stock
// Make the every option be the default i see it will be better
// for using this stock like this " Notify_Ex( id, "test message", "plugin name" ) == will show everything for all players
stock Notify_ExiSender, const szInput[ ], const szPluginName[ ], eNotifyType:iShowUserInfo 0ePrintType:iPrintDestination )
{
    new 
szOutputMAX_TEXT_LENGTH ], szTempMAX_NAME_LENGTH ]
    
    if( !
szInput] )
    {
        
log_amx("Warning! There's nothing to send to players")
        return;
    }
    
    
//if(szPluginName[ 0 ] ) Why you are checking if the plugin name are found? if is not found then will show as empty
    //    formatex(szOutput, charsmax(szOutput), "[%s] ", szPluginName)

    
switch( iShowUserInfo // Use a formatex just one time for everything !!
    
{
        case 
0// 0 = Everything
        
{
            new 
szNameMAX_NAME_LENGTH ]
            
get_user_nameiSenderszNamecharsmaxszName ) )
            
formatexszTempcharsmaxszTemp ), "%s (ID: %i)"szNameiSender )
        }
        case 
ID_ONLY:
        {
            
formatexszTempcharsmaxszTemp ), "(ID: %i)"iSender )
        }
        case 
NAME_ONLY:
        {
            
get_user_nameiSenderszTempcharsmaxszTemp ) ) //faster than adding to format
        
}
    }

    
formatexszOutputcharsmaxszOutput ), "%s %s %s"szPluginNameiSender szTemp ""szInput )
    
trimszOutput )// iam not sure if it will work but try, if "plugin name" or "iSender" is not founded will be empty with adding space i think this will remove the space
    
    
new szPlayersMAX_PLAYERS ], iPnum
    get_players
(szPlayersiPnum)
    
    for( new 
iPlayeriiPnumi++) // Use the loop for one time
    
{
        
iPlayer szPlayers]
        
        switch( 
iPrintDestination )
        {
            case 
0:
            {
                
console_printiPlayerszOutput )
                
client_printiPlayerprint_chatszOutput )
            }
            case 
PRINT_CHAT:
            {
                
client_printiPlayerprint_chatszOutput )
            }
            
            case 
PRINT_CONSOLE:
            {
                
console_printiPlayerszOutput)
            }
        }
    }

Edit: After reading the comments i understood everything
__________________
Youtube.com/Supremache

Bank System [Nvault - SQL Support]
VIP System
  • If you think it's that simple, then do it yourself.

Last edited by Supremache; 01-26-2022 at 06:54.
Supremache 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 05:29.


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