Page 1 of 1

[TuT] Cum sa testezi eficenta si viteza unei native.

Posted: 08 Jun 2017, 16:44
by Fuffy
Cu aceste functii puteti sa testati care functie/nativa e mai eficienta/rapida, multumesc lui black rose, exemplu+functia in sine mai jos:

Code: Select all

#include <amxmodx>
#include <fun>
#include <fakemeta>


#define debug_start()		tickcount()

#define debug_stop(%0)		( %0 = tickcount() - %0 )
#define debug_loop()		for( new x; x < 1000000; x++ )

#define TimerSeconds(%0)	( %0 / 1000 % 60 )
#define TimerMilliseconds(%0)	( %0 % 1000 )

stock TimerConvert( timer, sztimer[], maxchars=0 ) 
{  
	formatex( sztimer, maxchars, "%02d seconds, %03d miliseconds.", TimerSeconds(timer) , TimerMilliseconds(timer) );
}

new gTest1, gTest2;

public plugin_init( )
{
	register_clcmd( "say /test" , "test" );
	register_clcmd( "say /test2", "test2" );
	register_clcmd( "say /result", "res" );
}

public test( id )
{
	new iTimer = debug_start();

	debug_loop()
	{
		set_user_health( id, 250 );
	}

	debug_stop(iTimer );


	gTest1 = iTimer;
	
	return PLUGIN_HANDLED;
}

public test2( id )
{
	new iTimer = debug_start();

	debug_loop()
	{
		set_pev( id, pev_health, 250.0 );
	}

	debug_stop(iTimer );


	gTest2 = iTimer;
	
	return PLUGIN_HANDLED;
}

public res( id )
{
	new szTimer1[40];
	TimerConvert( gTest1, szTimer1, charsmax(szTimer1) );

	new szTimer2[40];
	TimerConvert( gTest2, szTimer2, charsmax(szTimer2) );

	client_print( id, print_chat, "Fun set_user_health run in: %s", szTimer1 );
	client_print( id, print_chat, "FakeMeta set_pev pev_heath run in: %s", szTimer2 );
	client_print( id, print_chat, "%s is much faster!", gTest1 > gTest2 ? "Fakemeta" : "Fun" );

	return PLUGIN_HANDLED;
}

Rezultat:

Code: Select all

Fun set_user_health run in: 00 seconds, 202 miliseconds.
FakeMeta set_pev pev_heath run in: 00 seconds, 390 miliseconds.
Fun is much faster!

Re: [TuT] Cum sa testezi eficenta si viteza unei native.

Posted: 14 Jun 2017, 19:13
by JaiLBreaK
what, format este mai rapid ca formatex

Re: [TuT] Cum sa testezi eficenta si viteza unei native.

Posted: 17 Jun 2017, 09:12
by Fuffy
Nu conteaza functia care o folosesc ca sa formatez stockul avand in vedere ca oricum o sa scoti stock-ul pentru un plugin adevarat, folosesti stock-ul doar ca compari functii/metode intre ele.

Re: [TuT] Cum sa testezi eficenta si viteza unei native.

Posted: 17 Jun 2017, 10:53
by JaiLBreaK
nu ma refeream la stockul tau, am inlocuit set_user_health( id, 250 ); si set_pev( id, pev_health, 250.0 ); cu formatex si format si format este mai rapid decat formatex

Re: [TuT] Cum sa testezi eficenta si viteza unei native.

Posted: 18 Jun 2017, 11:08
by Fuffy
1. Totul e facut de Black Rose de pe aliedmods nu de catre mine.
2. Ca sa popuplam mai bine topicul, ai putea sa arati cum ai facut asta si OutPut-ul ? Chiar daca pot sa fac si eu asta e pentru activiteate :P

Re: [TuT] Cum sa testezi eficenta si viteza unei native.

Posted: 19 Jun 2017, 16:55
by Lux0R^
JaiLBreaK wrote:nu ma refeream la stockul tau, am inlocuit set_user_health( id, 250 ); si set_pev( id, pev_health, 250.0 ); cu formatex si format si format este mai rapid decat formatex
cum nici functia random nu e un random ci un pseudo-random, asa si functia lui
in teorie pare totul ok, nu ?
ei bine uite ca ai uitat ce se intampla in spate : procesorul poate sa efectueze mai multe operatii deodata in timpul in care dai functia aia
Image
tu ce zici ?

Re: [TuT] Cum sa testezi eficenta si viteza unei native.

Posted: 20 Jun 2017, 00:41
by Fuffy
Lux0r, teoretic :P acele functii nu sunt chemate daca el nu foloseste copy-back-ul, nu ?

Oricum optez pentru formatex().

Re: [TuT] Cum sa testezi eficenta si viteza unei native.

Posted: 24 Jun 2017, 10:15
by Fuffy
o alta metoda ar fi asta:

Code: Select all

#include <amxmodx> 
#include <debug> 
#include <fun> 
#include <fakemeta> 

new fun, fm, total, times; 
const maxtimes = 5; 

public plugin_init() 
{ 
    register_clcmd( "test", "ptest" ); 
} 

public ptest(id) 
{ 
    new iStart1 = debug_cur_tick(); 
    debug_loop_fortick() 
    { 
        set_user_health(id, 250 ); 
    } 
    debug_stop_tick(iStart1); 

    new iStart2 = debug_cur_tick(); 
    debug_loop_fortick() 
    { 
        set_pev( id, pev_health, 250.0 ); 
    } 
    debug_stop_tick(iStart2); 

    if( debug_compare_ticks(iStart1, iStart2) == 1 ) 
    { 
        fun++; 
    } 
     
    else 
    { 
        fm++; 
    } 

    if( total < 100 ) 
    { 
        total++; 
        ptest(id); 
    } 
    else 
    { 
        debug_log( 5, "%s is faster(Fun: %i , Fm: %i, Total native calls: %i)!", fun > fm ? "set_user_health()" : "set_pev(id, pev_health, ... )", fun, fm, total ); 
         
        fm = 0; 
        fun = 0; 
        total = 0; 
         
        times++; 

        if( times < maxtimes ) 
            set_task( 3.0, "ptest", id ); 
    } 
     
    return PLUGIN_HANDLED; 
}  
Output:

Code: Select all

[DEBUG, SysTime: 1498256736, Map: fy_snow, Players: 1] set_user_health() is faster(Fun: 58 , Fm: 43, Total native calls: 100)!
[DEBUG, SysTime: 1498256743, Map: fy_snow, Players: 1] set_user_health() is faster(Fun: 63 , Fm: 38, Total native calls: 100)!
[DEBUG, SysTime: 1498256751, Map: fy_snow, Players: 1] set_user_health() is faster(Fun: 65 , Fm: 36, Total native calls: 100)!
[DEBUG, SysTime: 1498256758, Map: fy_snow, Players: 1] set_user_health() is faster(Fun: 64 , Fm: 37, Total native calls: 100)!
[DEBUG, SysTime: 1498256766, Map: fy_snow, Players: 1] set_user_health() is faster(Fun: 55 , Fm: 46, Total native calls: 100)!
link: https://forums.alliedmods.net/showthrea ... 725&page=3

Re: [TuT] Cum sa testezi eficenta si viteza unei native.

Posted: 24 Jun 2017, 11:05
by The Kalu
eficienta*

Re: [TuT] Cum sa testezi eficenta si viteza unei native.

Posted: 01 Jul 2017, 17:42
by Fuffy
Lord Kalu wrote:eficienta*
mersi, o sa corectez pe la anu.

Re: [TuT] Cum sa testezi eficenta si viteza unei native.

Posted: 01 Jul 2017, 23:05
by The Kalu
Fuffy wrote:
Lord Kalu wrote:eficienta*
mersi, o sa corectez pe la anu.
i don't care, poti edita si peste 100 de ani eu doar ti-am atras atentia ca ai scris gresit