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

Tutoriale scripting, cod si portiuni de cod.

Moderators: Moderatori ajutatori, Moderatori

Post Reply
User avatar
Fuffy
Membru, skill +1
Membru, skill +1
Posts: 299
Joined: 07 Jan 2016, 08:34
Detinator Steam: Da
CS Status: Citesc forumul eXtreamCS.com...!
Fond eXtream: 0
Contact:

08 Jun 2017, 15:44

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!
AMXX Blue e acum doar pe github.
IG-BOOST.org - Instagram Followers Best, Cheap, Reliable
User avatar
JaiLBreaK
Scripter eXtreamCS
Scripter eXtreamCS
Posts: 1696
Joined: 05 Jan 2016, 18:17
Detinator Steam: Nu
Detinator server CS: Da
Reputatie: Membru Club eXtreamCS (2 luni)
Scripter eXtreamCS
Fond eXtream: 0
Has thanked: 2 times
Been thanked: 7 times
Contact:

14 Jun 2017, 18:13

what, format este mai rapid ca formatex
Image
User avatar
Fuffy
Membru, skill +1
Membru, skill +1
Posts: 299
Joined: 07 Jan 2016, 08:34
Detinator Steam: Da
CS Status: Citesc forumul eXtreamCS.com...!
Fond eXtream: 0
Contact:

17 Jun 2017, 08:12

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.
AMXX Blue e acum doar pe github.
User avatar
JaiLBreaK
Scripter eXtreamCS
Scripter eXtreamCS
Posts: 1696
Joined: 05 Jan 2016, 18:17
Detinator Steam: Nu
Detinator server CS: Da
Reputatie: Membru Club eXtreamCS (2 luni)
Scripter eXtreamCS
Fond eXtream: 0
Has thanked: 2 times
Been thanked: 7 times
Contact:

17 Jun 2017, 09:53

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
Image
User avatar
Fuffy
Membru, skill +1
Membru, skill +1
Posts: 299
Joined: 07 Jan 2016, 08:34
Detinator Steam: Da
CS Status: Citesc forumul eXtreamCS.com...!
Fond eXtream: 0
Contact:

18 Jun 2017, 10:08

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
AMXX Blue e acum doar pe github.
Lux0R^
Scripter eXtreamCS
Scripter eXtreamCS
Posts: 1225
Joined: 13 Jul 2013, 15:31
Detinator Steam: Da
Reputatie: Scripter eXtreamCS
Moderator ajutator
Has thanked: 15 times
Been thanked: 9 times

19 Jun 2017, 15:55

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 ?
Pauza pana in iulie... licenta ^^

Fara pm-uri pentru pluginuri de zm/furien + tot ce tine de vip.

Codul Scripterului: scripting/codul-scripterului-t362300.html#p2754224
User avatar
Fuffy
Membru, skill +1
Membru, skill +1
Posts: 299
Joined: 07 Jan 2016, 08:34
Detinator Steam: Da
CS Status: Citesc forumul eXtreamCS.com...!
Fond eXtream: 0
Contact:

19 Jun 2017, 23:41

Lux0r, teoretic :P acele functii nu sunt chemate daca el nu foloseste copy-back-ul, nu ?

Oricum optez pentru formatex().
AMXX Blue e acum doar pe github.
User avatar
Fuffy
Membru, skill +1
Membru, skill +1
Posts: 299
Joined: 07 Jan 2016, 08:34
Detinator Steam: Da
CS Status: Citesc forumul eXtreamCS.com...!
Fond eXtream: 0
Contact:

24 Jun 2017, 09:15

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
AMXX Blue e acum doar pe github.
User avatar
The Kalu
Membru eXtream
Membru eXtream
Posts: 11953
Joined: 09 Oct 2010, 11:39
Detinator Steam: Da
Reputatie: Fost membru Club eXtreamCS (6 luni)
Restrictie moderator permanent
Restrictie schimbare nume
Nume anterior: Terra
Membrul anului 2017
Has thanked: 108 times
Been thanked: 269 times

24 Jun 2017, 10:05

eficienta*
User avatar
Fuffy
Membru, skill +1
Membru, skill +1
Posts: 299
Joined: 07 Jan 2016, 08:34
Detinator Steam: Da
CS Status: Citesc forumul eXtreamCS.com...!
Fond eXtream: 0
Contact:

01 Jul 2017, 16:42

Lord Kalu wrote:eficienta*
mersi, o sa corectez pe la anu.
AMXX Blue e acum doar pe github.
User avatar
The Kalu
Membru eXtream
Membru eXtream
Posts: 11953
Joined: 09 Oct 2010, 11:39
Detinator Steam: Da
Reputatie: Fost membru Club eXtreamCS (6 luni)
Restrictie moderator permanent
Restrictie schimbare nume
Nume anterior: Terra
Membrul anului 2017
Has thanked: 108 times
Been thanked: 269 times

01 Jul 2017, 22:05

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
Post Reply

Return to “Scripting”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 0 guests