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

~containi and != -1


Post New Thread Reply   
 
Thread Tools Display Modes
NiHiLaNTh
Way Past Expiration
Join Date: May 2009
Location: Latvia
Old 04-23-2015 , 03:59   Re: ~containi and != -1
Reply With Quote #11

because it makes code unreadable. Execution time difference is extremely small, so forget about it. Its not the thing, that should be optimized.
__________________

NiHiLaNTh is offline
Send a message via Skype™ to NiHiLaNTh
Freezo Begin
BANNED
Join Date: Mar 2014
Location: Morocco
Old 04-23-2015 , 04:40   Re: ~containi and != -1
Reply With Quote #12

Hmmm , oke thanks .
Freezo Begin is offline
claudiuhks
Yam Inside®™℠
Join Date: Jan 2010
Location: Living Randomly
Old 04-23-2015 , 08:44   Re: ~containi and != -1
Reply With Quote #13

You can get the execution time with my module called Execution Time, please search it in AMX Mod X -> Module Coding.

Quote:
Originally Posted by Freezo Begin View Post
Why you dont recommend to use it ?
Because contain and containi is made that way so it returns values that do not need to be computed by ~, & and |. If you do not use the default way and add style do your code that way, you might get problems in the future regarding the returned values of the function.
__________________

Last edited by claudiuhks; 04-23-2015 at 09:08.
claudiuhks is offline
Send a message via MSN to claudiuhks Send a message via Yahoo to claudiuhks Send a message via Skype™ to claudiuhks
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 04-23-2015 , 12:15   Re: ~containi and != -1
Reply With Quote #14

Code:
#include <amxmodx> #define runs 10 #define loops 100000000 // That is 100 million #define TimerStart()            tickcount() #define TimerMid(%0)            ( tickcount() - %0 ) #define TimerStop(%0)         ( %0 = tickcount() - %0 ) #define TimerDays(%0)         ( %0 / 86400000 ) #define TimerHours(%0)      ( %0 % 86400000 / 3600000 ) #define TimerMinutes(%0)        ( %0 % 3600000 / 60000 ) #define TimerSeconds(%0)        ( %0 % 60000 / 1000 ) #define TimerMilliseconds(%0)   ( %0 % 1000 ) public plugin_init() {     register_plugin("Test Plugin 3", "", "[ --{-@ ]");         new test = -1;     new hTimer = TimerStart();     new Time;     for ( new i = 0 ; i < runs ; i++ ) {         hTimer = TimerStart();         for ( new j = 0 ; j < loops ; j++ ) {              if ( test != -1 ) { }         }         TimerStop(hTimer);         server_print("1st method, run %d: %ds, %dms.", i + 1, TimerSeconds(hTimer), TimerMilliseconds(hTimer));         Time += hTimer;     }     server_print("1st method, total time: %dm, %ds, %dms", TimerMinutes(Time), TimerSeconds(Time), TimerMilliseconds(Time));     Time /= runs     server_print("1nd method, average time: %ds, %dms.^n", TimerSeconds(Time), TimerMilliseconds(Time));     Time = 0;     for ( new i = 0 ; i < runs ; i++ ) {         hTimer = TimerStart();         for ( new j = 0 ; j < loops ; j++ ) {              if ( ~test ) { }         }         TimerStop(hTimer);         server_print("2nd method, run %d: %ds, %dms.", i + 1, TimerSeconds(hTimer), TimerMilliseconds(hTimer));         Time += hTimer;     }     server_print("2nd method, total time: %dm, %ds, %dms", TimerMinutes(Time), TimerSeconds(Time), TimerMilliseconds(Time));     Time /= runs     server_print("2nd method, average time: %ds, %dms.^n", TimerSeconds(Time), TimerMilliseconds(Time));     Time = 0;     for ( new i = 0 ; i < runs ; i++ ) {         hTimer = TimerStart();         for ( new j = 0 ; j < loops ; j++ ) {         }         TimerStop(hTimer);         server_print("nothing at all, run %d: %ds, %dms.", i + 1, TimerSeconds(hTimer), TimerMilliseconds(hTimer));         Time += hTimer;     }     server_print("nothing at all, total time: %dm, %ds, %dms", TimerMinutes(Time), TimerSeconds(Time), TimerMilliseconds(Time));     Time /= runs     server_print("nothing at all, average time: %ds, %dms.", TimerSeconds(Time), TimerMilliseconds(Time)); }

Code:
1st method, run 1: 4s, 563ms.
1st method, run 2: 4s, 564ms.
1st method, run 3: 4s, 561ms.
1st method, run 4: 4s, 564ms.
1st method, run 5: 4s, 563ms.
1st method, run 6: 4s, 565ms.
1st method, run 7: 4s, 559ms.
1st method, run 8: 4s, 565ms.
1st method, run 9: 4s, 561ms.
1st method, run 10: 4s, 551ms.
1st method, total time: 0m, 45s, 616ms
1nd method, average time: 4s, 561ms.

2nd method, run 1: 4s, 563ms.
2nd method, run 2: 4s, 558ms.
2nd method, run 3: 4s, 564ms.
2nd method, run 4: 4s, 561ms.
2nd method, run 5: 4s, 566ms.
2nd method, run 6: 4s, 562ms.
2nd method, run 7: 4s, 564ms.
2nd method, run 8: 4s, 561ms.
2nd method, run 9: 4s, 565ms.
2nd method, run 10: 4s, 565ms.
2nd method, total time: 0m, 45s, 629ms
2nd method, average time: 4s, 562ms.

nothing at all, run 1: 1s, 386ms.
nothing at all, run 2: 1s, 386ms.
nothing at all, run 3: 1s, 387ms.
nothing at all, run 4: 1s, 386ms.
nothing at all, run 5: 1s, 384ms.
nothing at all, run 6: 1s, 386ms.
nothing at all, run 7: 1s, 386ms.
nothing at all, run 8: 1s, 386ms.
nothing at all, run 9: 1s, 385ms.
nothing at all, run 10: 1s, 386ms.
nothing at all, total time: 0m, 13s, 858ms
nothing at all, average time: 1s, 385ms.
__________________

Last edited by Black Rose; 04-23-2015 at 12:16.
Black Rose is offline
^SmileY
Veteran Member
Join Date: Jan 2010
Location: Brazil [<o>]
Old 04-23-2015 , 12:21   Re: ~containi and != -1
Reply With Quote #15

for that native will return -1, i do not see a valid reason to use ~ like fysiks said.

Ps.

Code:
/**
 * Tests whether a string is found inside another string.
 *
 * @param source        String to search in.
 * @param string        Substring to find inside the original string.
 *
 * @return                -1 on failure (no match found). Any other value
 *                        indicates a position in the string where the match starts.
 */
native contain(const source[], const string[]);
@fysiks said: "I wouldn't recommend it here because it obfuscates the code making it unreadable."

Ops: I ony re-reply this because the include means that native will return -1
__________________
Projects:

- See my Git Hub: https://github.com/SmileYzn
PHP Code:
set_pcvar_num(pCvar, !get_pcvar_num(pCvar)); 

Last edited by ^SmileY; 04-23-2015 at 12:22.
^SmileY is offline
Send a message via MSN to ^SmileY Send a message via Skype™ to ^SmileY
Freezo Begin
BANNED
Join Date: Mar 2014
Location: Morocco
Old 04-23-2015 , 12:39   Re: ~containi and != -1
Reply With Quote #16

hmm thanks .
@Black Rose , thanks
But how about this ?
Code:
#define MILLIS (10000) getTime() {     new time0,  time1, time2,   i;     time0 = tickcount()     for (i = 0; i < MILLIS; i++)     {         server_print("%d",100)     }     time1 = tickcount();     for (i = 0; i < MILLIS; i++)     {         server_print("100")     }     time2 = tickcount();     server_print("getTime 1: %04d || getTime 2: %04d", time1 - time0, time2 - time1) }
Freezo Begin is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 04-23-2015 , 21:03   Re: ~containi and != -1
Reply With Quote #17

STOP caring about the execution time difference. There is no point. It will make no difference in the outcome of your code. There are many other things that can be done to ensure your code runs as fast as it needs to.
__________________
fysiks 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 19:22.


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