Raised This Month: $ Target: $400
 0% 

Teoretical Help


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 06-22-2011 , 00:17   Re: Teoretical Help
Reply With Quote #1

Quote:
Originally Posted by SnoW View Post
I do not get your point. Do you seriously mean he should use natives to make the plugins func together? Not just in variable sharing but in general he should not create new natives.
After some profiling, natives are proven to be faster than callfuncs.

Code:
date: Tue Jun 21 22:57:35 2011 map: de_dust
type |                             name |      calls | time / min / max
-------------------------------------------------------------------
   n |                      test_native |      10000 | 0.032491 / 0.000002 / 0.003416
   f |                    test_callfunc |      10000 | 0.054404 / 0.000004 / 0.001982

   n |                 test_native_ints |      10000 | 0.030858 / 0.000002 / 0.001723
   f |               test_callfunc_ints |      10000 | 0.089962 / 0.000007 / 0.004380

   n |               test_native_floats |      10000 | 0.028812 / 0.000002 / 0.000865
   f |             test_callfunc_floats |      10000 | 0.084756 / 0.000007 / 0.002068

   n |              test_native_strings |      10000 | 0.034963 / 0.000002 / 0.005082
   f |            test_callfunc_strings |      10000 | 0.116257 / 0.000009 / 0.001790
1 natives, 0 public callbacks, 12 function calls were not executed.
Here is the code that was used to test:

PHP Code:
#include < amxmodx >

native test_native();
native test_native_ints(int1int2);
native Float:test_native_floats(Float:float1Float:float2);
native test_native_strings(const str1[], const str2[], output[], len);

stock test_callfunc()
{
    new 
funcid get_func_id("_test_callfunc");
    
    if(
funcid != -1)
    {
        
callfunc_begin_i(funcid);
        return 
callfunc_end();
    }
    
    return 
0;
}

stock test_callfunc_ints(int1int2)
{
    new 
funcid get_func_id("_test_callfunc_ints");
    
    if(
funcid != -1)
    {
        
callfunc_begin_i(funcid);
        
callfunc_push_int(int1);
        
callfunc_push_int(int2);
        return 
callfunc_end();
    }
    
    return 
0;
}

stock Float:test_callfunc_floats(Float:float1Float:float2)
{
    new 
funcid get_func_id("_test_callfunc_floats");
    
    if(
funcid != -1)
    {
        
callfunc_begin_i(funcid);
        
callfunc_push_float(float1);
        
callfunc_push_float(float2);
        return 
Float:callfunc_end();
    }
    
    return 
0.0;
}

stock test_callfunc_strings(const str1[], const str2[], output[], len)
{
    new 
funcid get_func_id("_test_callfunc_strings");
    
    if(
funcid != -1)
    {
        
callfunc_begin_i(funcid);
        
callfunc_push_str(str1false);
        
callfunc_push_str(str2false);
        
callfunc_push_str(output);
        
callfunc_push_int(len);
        return 
callfunc_end();
    }
    
    return 
0;
}

public 
plugin_init( )
{
    
register_plugin"Profiler Test""0.0.1""Exolent" );
    
    
register_srvcmd"profile""CmdProfile" );
}

public 
plugin_natives( )
{
    
register_native"test_native""_test_native" );
    
register_native"test_native_ints""_test_native_ints" );
    
register_native"test_native_floats""_test_native_floats" );
    
register_native"test_native_strings""_test_native_strings");
}

public 
_test_nativeiPluginiParams )
{
    return 
1;
}

public 
_test_native_intsiPluginiParams )
{
    return ( 
get_param) + get_param) );
}

public 
Float:_test_native_floatsiPluginiParams )
{
    return ( 
get_param_f) + get_param_f) );
}

public 
_test_native_stringsszString1[ ], szString2[ ], szOutput[ ], iLen )
{
    
param_convert);
    
param_convert);
    
param_convert);
    
    return 
formatexszOutputiLen"%s %s"szString1szString2 );
}

public 
_test_callfunc( )
{
    return 
1;
}

public 
_test_callfunc_intsiInt1iInt2 )
{
    return ( 
iInt1 iInt2 );
}

public 
Float:_test_callfunc_floatsFloat:flFloat1Float:flFloat2 )
{
    return ( 
flFloat1 flFloat2 );
}

public 
_test_callfunc_stringsszString1[ ], szString2[ ], szOutput[ ], iLen )
{
    return 
formatexszOutputiLen"%s %s"szString1szString2 );
}

public 
CmdProfile( )
{
    new 
output[32];
    for( new 
010000i++ )
    {
        
test_native();
        
test_native_ints(12);
        
test_native_floats(1.02.0);
        
test_native_strings("Ohhai""there"outputcharsmax(output));
        
test_callfunc();
        
test_callfunc_ints(12);
        
test_callfunc_floats(1.02.0);
        
test_callfunc_strings("Ohhai""there"outputcharsmax(output));
    }
    
    
log_amx"Finished Profile" );
    
    return 
PLUGIN_HANDLED;

Here is a profile of them in separate plugins (even a little advantage for callfunc with the plugin/funcid caching):
Code:
date: Tue Jun 21 23:07:41 2011 map: de_dust
type |                             name |      calls | time / min / max
-------------------------------------------------------------------
   n |                      test_native |      10000 | 0.018990 / 0.000001 / 0.004626
   f |                    test_callfunc |      10000 | 0.041347 / 0.000003 / 0.001377

   n |                 test_native_ints |      10000 | 0.016021 / 0.000001 / 0.001074
   f |               test_callfunc_ints |      10000 | 0.070727 / 0.000006 / 0.001660

   n |               test_native_floats |      10000 | 0.019196 / 0.000001 / 0.001857
   f |             test_callfunc_floats |      10000 | 0.078072 / 0.000006 / 0.001907

   n |              test_native_strings |      10000 | 0.019567 / 0.000001 / 0.001247
   f |            test_callfunc_strings |      10000 | 0.115104 / 0.000008 / 0.005962
0 natives, 0 public callbacks, 3 function calls were not executed.
Here are the 2 test plugins that were used:

PHP Code:
#include < amxmodx >
#include < profiler >

native test_native();
native test_native_ints(int1int2);
native Float:test_native_floats(Float:float1Float:float2);
native test_native_strings(const str1[], const str2[], output[], len);

new 
g_callfunc_plugin = -1;
new 
g_callfunc_func = -1;
new 
g_callfunc_func_ints = -1;
new 
g_callfunc_func_floats = -1;
new 
g_callfunc_func_strings = -1;

stock test_callfunc()
{
    if(
g_callfunc_func != -1)
    {
        
callfunc_begin_i(g_callfunc_funcg_callfunc_plugin);
        return 
callfunc_end();
    }
    
    return 
0;
}

stock test_callfunc_ints(int1int2)
{
    if(
g_callfunc_func_ints != -1)
    {
        
callfunc_begin_i(g_callfunc_func_intsg_callfunc_plugin);
        
callfunc_push_int(int1);
        
callfunc_push_int(int2);
        return 
callfunc_end();
    }
    
    return 
0;
}

stock Float:test_callfunc_floats(Float:float1Float:float2)
{
    if(
g_callfunc_func_floats != -1)
    {
        
callfunc_begin_i(g_callfunc_func_floatsg_callfunc_plugin);
        
callfunc_push_float(float1);
        
callfunc_push_float(float2);
        return 
Float:callfunc_end();
    }
    
    return 
0.0;
}

stock test_callfunc_strings(const str1[], const str2[], output[], len)
{
    if(
g_callfunc_func_strings != -1)
    {
        
callfunc_begin_i(g_callfunc_func_stringsg_callfunc_plugin);
        
callfunc_push_str(str1false);
        
callfunc_push_str(str2false);
        
callfunc_push_str(output);
        
callfunc_push_int(len);
        return 
callfunc_end();
    }
    
    return 
0;
}

public 
plugin_init( )
{
    
register_plugin"Profiler Test""0.0.1""Exolent" );
    
    
register_srvcmd"profile""CmdProfile" );
    
    new 
pluginsnum get_pluginsnum( );
    
    for( new 
0pluginsnumi++ )
    {
        
g_callfunc_func get_func_id"test_callfunc");
        
        if( 
g_callfunc_func != -)
        {
            
g_callfunc_plugin i;
            
g_callfunc_func_ints get_func_id"test_callfunc_ints");
            
g_callfunc_func_floats get_func_id"test_callfunc_floats");
            
g_callfunc_func_strings get_func_id"test_callfunc_strings");
            
            break;
        }
    }
}

public 
CmdProfile( )
{
    new 
output[32];
    for( new 
010000i++ )
    {
        
test_native();
        
test_native_ints(12);
        
test_native_floats(1.02.0);
        
test_native_strings("Ohhai""there"outputcharsmax(output));
        
test_callfunc();
        
test_callfunc_ints(12);
        
test_callfunc_floats(1.02.0);
        
test_callfunc_strings("Ohhai""there"outputcharsmax(output));
    }
    
    
log_amx"Finished Profile" );
    
    return 
PLUGIN_HANDLED;

PHP Code:
#include < amxmodx >

public plugin_init()
{
    
register_plugin"Profiler Native Helper""0.0.1""Exolent" );
}

public 
plugin_natives( )
{
    
register_native"test_native""_test_native" );
    
register_native"test_native_ints""_test_native_ints" );
    
register_native"test_native_floats""_test_native_floats" );
    
register_native"test_native_strings""_test_native_strings");
}

public 
_test_nativeiPluginiParams )
{
    return 
1;
}

public 
_test_native_intsiPluginiParams )
{
    return ( 
get_param) + get_param) );
}

public 
Float:_test_native_floatsiPluginiParams )
{
    return ( 
get_param_f) + get_param_f) );
}

public 
_test_native_stringsszString1[ ], szString2[ ], szOutput[ ], iLen )
{
    
param_convert);
    
param_convert);
    
param_convert);
    
    return 
formatexszOutputiLen"%s %s"szString1szString2 );
}

public 
test_callfunc( )
{
    return 
1;
}

public 
test_callfunc_intsiInt1iInt2 )
{
    return ( 
iInt1 iInt2 );
}

public 
Float:test_callfunc_floatsFloat:flFloat1Float:flFloat2 )
{
    return ( 
flFloat1 flFloat2 );
}

public 
test_callfunc_stringsszString1[ ], szString2[ ], szOutput[ ], iLen )
{
    return 
formatexszOutputiLen"%s %s"szString1szString2 );

__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Old 06-22-2011, 06:26
SnoW
This message has been deleted by SnoW.
Old 06-22-2011, 06:32
SnoW
This message has been deleted by SnoW.
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 23:34.


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