|
Veteran Member
Join Date: Feb 2007
Location: Tennessee
|

06-22-2011
, 00:17
Re: Teoretical Help
|
#2
|
Quote:
Originally Posted by SnoW
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(int1, int2);
native Float:test_native_floats(Float:float1, Float: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(int1, int2)
{
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:float1, Float: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(str1, false);
callfunc_push_str(str2, false);
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", 1 );
}
public _test_native( iPlugin, iParams )
{
return 1;
}
public _test_native_ints( iPlugin, iParams )
{
return ( get_param( 1 ) + get_param( 2 ) );
}
public Float:_test_native_floats( iPlugin, iParams )
{
return ( get_param_f( 1 ) + get_param_f( 2 ) );
}
public _test_native_strings( szString1[ ], szString2[ ], szOutput[ ], iLen )
{
param_convert( 1 );
param_convert( 2 );
param_convert( 3 );
return formatex( szOutput, iLen, "%s %s", szString1, szString2 );
}
public _test_callfunc( )
{
return 1;
}
public _test_callfunc_ints( iInt1, iInt2 )
{
return ( iInt1 + iInt2 );
}
public Float:_test_callfunc_floats( Float:flFloat1, Float:flFloat2 )
{
return ( flFloat1 + flFloat2 );
}
public _test_callfunc_strings( szString1[ ], szString2[ ], szOutput[ ], iLen )
{
return formatex( szOutput, iLen, "%s %s", szString1, szString2 );
}
public CmdProfile( )
{
new output[32];
for( new i = 0; i < 10000; i++ )
{
test_native();
test_native_ints(1, 2);
test_native_floats(1.0, 2.0);
test_native_strings("Ohhai", "there", output, charsmax(output));
test_callfunc();
test_callfunc_ints(1, 2);
test_callfunc_floats(1.0, 2.0);
test_callfunc_strings("Ohhai", "there", output, charsmax(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(int1, int2);
native Float:test_native_floats(Float:float1, Float: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_func, g_callfunc_plugin);
return callfunc_end();
}
return 0;
}
stock test_callfunc_ints(int1, int2)
{
if(g_callfunc_func_ints != -1)
{
callfunc_begin_i(g_callfunc_func_ints, g_callfunc_plugin);
callfunc_push_int(int1);
callfunc_push_int(int2);
return callfunc_end();
}
return 0;
}
stock Float:test_callfunc_floats(Float:float1, Float:float2)
{
if(g_callfunc_func_floats != -1)
{
callfunc_begin_i(g_callfunc_func_floats, g_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_strings, g_callfunc_plugin);
callfunc_push_str(str1, false);
callfunc_push_str(str2, false);
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 i = 0; i < pluginsnum; i++ )
{
g_callfunc_func = get_func_id( "test_callfunc", i );
if( g_callfunc_func != -1 )
{
g_callfunc_plugin = i;
g_callfunc_func_ints = get_func_id( "test_callfunc_ints", i );
g_callfunc_func_floats = get_func_id( "test_callfunc_floats", i );
g_callfunc_func_strings = get_func_id( "test_callfunc_strings", i );
break;
}
}
}
public CmdProfile( )
{
new output[32];
for( new i = 0; i < 10000; i++ )
{
test_native();
test_native_ints(1, 2);
test_native_floats(1.0, 2.0);
test_native_strings("Ohhai", "there", output, charsmax(output));
test_callfunc();
test_callfunc_ints(1, 2);
test_callfunc_floats(1.0, 2.0);
test_callfunc_strings("Ohhai", "there", output, charsmax(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", 1 );
}
public _test_native( iPlugin, iParams )
{
return 1;
}
public _test_native_ints( iPlugin, iParams )
{
return ( get_param( 1 ) + get_param( 2 ) );
}
public Float:_test_native_floats( iPlugin, iParams )
{
return ( get_param_f( 1 ) + get_param_f( 2 ) );
}
public _test_native_strings( szString1[ ], szString2[ ], szOutput[ ], iLen )
{
param_convert( 1 );
param_convert( 2 );
param_convert( 3 );
return formatex( szOutput, iLen, "%s %s", szString1, szString2 );
}
public test_callfunc( )
{
return 1;
}
public test_callfunc_ints( iInt1, iInt2 )
{
return ( iInt1 + iInt2 );
}
public Float:test_callfunc_floats( Float:flFloat1, Float:flFloat2 )
{
return ( flFloat1 + flFloat2 );
}
public test_callfunc_strings( szString1[ ], szString2[ ], szOutput[ ], iLen )
{
return formatex( szOutput, iLen, "%s %s", szString1, szString2 );
}
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw
I love you exolent!
|
|
|