Veteran Member
Join Date: Aug 2015
Location: Dreams, zz
|
01-28-2016
, 00:34
Re: amxmodx profiler
|
#120
|
Some benchmarks
Hi folks, I am here sharing some benchmarks.
Dynamic array
I did a benchmark between a static array and a dynamic array and I came here to share the results. It is just to see how big the difference could be. And as the same as tries and static arrays, you should use dynamic arrays, when it makes sense to it, i.e., they fit the well the problem solving.
Code:
date: Thu Jan 28 03:48:10 2016 map: de_dust2
type | name | calls | time / min / max
-------------------------------------------------------------------
n | register_plugin | 1 | 0.000009 / 0.000009 / 0.000009
n | register_srvcmd | 1 | 0.000069 / 0.000069 / 0.000069
n | ArrayCreate | 1 | 0.000002 / 0.000002 / 0.000002
n | ArrayPushCell | 32 | 0.000002 / 0.000000 / 0.000000
n | server_cmd | 1 | 0.000006 / 0.000006 / 0.000006
n | ArrayGetCell | 32000000 | 2.712061 / 0.000000 / 0.009609
p | cmd_go | 1 | 0.220705 / 0.220705 / 0.220705
p | plugin_init | 1 | 0.000005 / 0.000005 / 0.000005
f | UseStaticArray | 1000000 | 0.801795 / 0.000000 / 0.004913
f | UseDynamicArray | 1000000 | 28.758015 / 0.000016 / 0.034018
0 natives, 0 public callbacks, 2 function calls were not executed.
This was the source code used:
Spoiler
Code:
#include <amxmodx>
#include <amxmisc>
#define PLUGIN "Arrays Benchmark"
#define AUTHOR "stupok/addons zz"
#define VERSION "1.0"
new g_array_size = 32
new g_current_element
new Array: g_DynamicArray
new g_StaticArray[] =
{
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32
}
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
register_srvcmd( "go", "cmd_go" )
g_DynamicArray = ArrayCreate( 1 )
for( new index = 0; index < g_array_size; index++ )
{
ArrayPushCell( g_DynamicArray, g_StaticArray[ index ] )
}
}
public cmd_go()
{
new index
for( index = 0; index < 1000000; index++ )
{
UseStaticArray()
}
for( index = 0; index < 1000000; index++ )
{
UseDynamicArray()
}
server_cmd( "quit" )
}
UseStaticArray()
{
static index
for( index = 0; index < g_array_size; index++ )
{
g_current_element = g_StaticArray[ index ]
g_current_element++
}
}
UseDynamicArray()
{
static index
for( index = 0; index < g_array_size; index++ )
{
g_current_element = ArrayGetCell( g_DynamicArray, index )
g_current_element++
}
}
is_user_connect
Looks like is better use ' is_user_connect' instead of cache it's value, because the diference seen insignificant.
Code:
date: Fri Jan 29 01:58:47 2016 map: de_dust2
type | name | calls | time / min / max
-------------------------------------------------------------------
n | register_plugin | 1 | 0.000011 / 0.000011 / 0.000011
n | register_srvcmd | 1 | 0.000114 / 0.000114 / 0.000114
n | server_cmd | 1 | 0.000008 / 0.000008 / 0.000008
n | is_user_connected | 32000000 | 2.580960 / 0.000000 / 0.014820
p | cmd_go | 1 | 0.266977 / 0.266977 / 0.266977
p | plugin_init | 1 | 0.000003 / 0.000003 / 0.000003
f | use_user_connected | 1000000 | 5.494115 / 0.000000 / 0.059881
f | use_cached_value | 1000000 | 1.743552 / 0.000001 / 0.021680
0 natives, 0 public callbacks, 2 function calls were not executed.
This was the source code used:
Spoiler
Code:
#include <amxmodx>
#include <amxmisc>
#define PLUGIN "Arrays Benchmark"
#define AUTHOR "stupok/addons zz"
#define VERSION "1.0"
new g_array_size = 32
new g_unused_value
new g_StaticArray[] =
{
1, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0
}
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
register_srvcmd( "go", "cmd_go" )
}
public cmd_go()
{
new index
g_unused_value = 0
for( index = 0; index < 1000000; index++ )
{
use_user_connected()
}
g_unused_value = 0
for( index = 0; index < 1000000; index++ )
{
use_cached_value()
}
server_cmd( "quit" )
}
use_user_connected()
{
static index
for( index = 1; index <= g_array_size; index++ )
{
if( is_user_connected( index ) )
{
g_unused_value++
}
}
}
use_cached_value()
{
static index
for( index = 0; index < g_array_size; index++ )
{
if( g_StaticArray[ index ] )
{
g_unused_value++
}
}
}
cs_get_user_team
' cs_get_user_team' vs cached value benchmark.
Code:
date: Fri Jan 29 03:21:04 2016 map: de_dust2
type | name | calls | time / min / max
-------------------------------------------------------------------
n | register_plugin | 1 | 0.000009 / 0.000009 / 0.000009
n | register_srvcmd | 1 | 0.000099 / 0.000099 / 0.000099
n | get_players | 1 | 0.000003 / 0.000003 / 0.000003
n | cs_get_user_team | 31000031 | 7.618567 / 0.000000 / 0.023226
n | server_cmd | 1 | 0.000006 / 0.000006 / 0.000006
p | cmd_go | 1 | 0.208685 / 0.208685 / 0.208685
p | plugin_init | 1 | 0.000002 / 0.000002 / 0.000002
f | use_get_user_team | 1000000 | 8.162432 / 0.000000 / 0.016805
f | use_cached_value | 1000000 | 1.997416 / 0.000002 / 0.003139
0 natives, 0 public callbacks, 2 function calls were not executed.
This was the source code used:
Spoiler
Code:
#include <amxmodx>
#include <amxmisc>
#include <cstrike>
#define PLUGIN "Arrays Benchmark"
#define AUTHOR "stupok/addons zz"
#define VERSION "1.0"
new g_cached_value[33]
new g_unuseful_value1
new g_unuseful_value2
new g_unuseful_value3
new g_unuseful_value4
new g_players_count
new g_players[32]
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
register_srvcmd( "go", "cmd_go" )
}
public cmd_go()
{
new index
get_players( g_players, g_players_count )
for( new index = 0; index < g_players_count; index++ )
{
g_cached_value[ g_players[ index ] ] = _:cs_get_user_team( g_players[ index ] )
}
g_unuseful_value1 = 0
g_unuseful_value2 = 0
g_unuseful_value3 = 0
g_unuseful_value4 = 0
for( index = 0; index < 1000000; index++ )
{
use_get_user_team()
}
g_unuseful_value1 = 0
g_unuseful_value2 = 0
g_unuseful_value3 = 0
g_unuseful_value4 = 0
for( index = 0; index < 1000000; index++ )
{
use_cached_value()
}
server_cmd( "quit" )
}
use_get_user_team()
{
static index
for( index = 0; index < g_players_count; index++ )
{
switch( cs_get_user_team( g_players[ index ] ) )
{
case CS_TEAM_CT : g_unuseful_value1++
case CS_TEAM_T : g_unuseful_value2++
case CS_TEAM_SPECTATOR : g_unuseful_value3++
default : g_unuseful_value4++
}
}
}
use_cached_value()
{
static index
for( index = 0; index < g_players_count; index++ )
{
switch( g_cached_value[ g_players[ index ] ] )
{
case CS_TEAM_CT : g_unuseful_value1++
case CS_TEAM_T : g_unuseful_value2++
case CS_TEAM_SPECTATOR : g_unuseful_value3++
default : g_unuseful_value4++
}
}
}
is_user_alive
' is_user_alive' vs cached value benchmark.
Code:
date: Fri Jan 29 03:34:38 2016 map: de_dust2
type | name | calls | time / min / max
-------------------------------------------------------------------
n | register_plugin | 1 | 0.000010 / 0.000010 / 0.000010
n | register_srvcmd | 1 | 0.000099 / 0.000099 / 0.000099
n | get_players | 1 | 0.000005 / 0.000005 / 0.000005
n | is_user_alive | 31000031 | 2.379797 / 0.000000 / 0.002604
n | server_cmd | 1 | 0.000007 / 0.000007 / 0.000007
p | cmd_go | 1 | 0.199224 / 0.199224 / 0.199224
p | plugin_init | 1 | 0.000003 / 0.000003 / 0.000003
f | use_user_alive | 1000000 | 4.456642 / 0.000000 / 0.009792
f | use_cached_value | 1000000 | 1.314150 / 0.000001 / 0.002849
0 natives, 0 public callbacks, 2 function calls were not executed.
This was the source code used:
Spoiler
Code:
#include <amxmodx>
#include <amxmisc>
#include <cstrike>
#define PLUGIN "Arrays Benchmark"
#define AUTHOR "stupok/addons zz"
#define VERSION "1.0"
new g_cached_value[33]
new g_unuseful_value1
new g_players_count
new g_players[32]
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
register_srvcmd( "go", "cmd_go" )
}
public cmd_go()
{
new index
get_players( g_players, g_players_count )
for( new index = 0; index < g_players_count; index++ )
{
g_cached_value[ g_players[ index ] ] = is_user_alive( g_players[ index ] )
}
g_unuseful_value1 = 0
for( index = 0; index < 1000000; index++ )
{
use_user_alive()
}
g_unuseful_value1 = 0
for( index = 0; index < 1000000; index++ )
{
use_cached_value()
}
server_cmd( "quit" )
}
use_user_alive()
{
static index
for( index = 0; index < g_players_count; index++ )
{
if( is_user_alive( g_players[ index ] ) )
{
g_unuseful_value1++
}
}
}
use_cached_value()
{
static index
for( index = 0; index < g_players_count; index++ )
{
if( g_cached_value[ g_players[ index ] ] )
{
g_unuseful_value1++
}
}
}
__________________
Last edited by addons_zz; 01-29-2016 at 00:36.
Reason: spelling fix
|
|