[ INC ] [ RUNTIME ] High-speed alternatives to the default AMX Mod X functions.

For scripting examples for learning how to use AMXX.
User avatar
Archive-Poster
Posts: 1136
Gender:
United States of America

[ INC ] [ RUNTIME ] High-speed alternatives to the default AMX Mod X functions.

Post by Archive-Poster »

This include currently contains faster alternatives to the following AMX Mod X core functions:
clamp( value, min = cellmin, max = cellmax );
max( value1, value2 );
min( value1, value2 );
random( max );
toupper( c );
tolower( c );
swapchars( c );
And also the following functions:
random_num(a, b);
random_float(Float:a, Float:b);
str_to_num(const string[]);
unregister_forward(_forwardType, registerId, post=0);
The functions provided in this include use less CPU and RAM compared to the default ones,
thanks to simplified logic and reduced memory allocation through macros ( when possible ).

More function-like macros and stocks will be added in the future.


Below are the profiling results for each function.

Functions terminated in '_R' are the faster ones provided by this include.

Each instance of flTime below is the ~'time spent' by the function in a different profiling moment.



swapchars_R( 1738272608 );
flTime: 0.000791
flTime: 0.000813
flTime: 0.000801

swapchars( 1738272608 );
flTime: 0.001807
flTime: 0.001838
flTime: 0.001890
Result: swapchars_R performed 2.28 times faster than swapchars.
toupper_R( 'd' );
flTime: 0.000381
flTime: 0.000377
flTime: 0.000382

toupper( 'd' );
flTime: 0.009422
flTime: 0.009378
flTime: 0.009560
Result: toupper_R performed 24.87 times faster than toupper.
tolower_R( 'D' );
flTime: 0.000377
flTime: 0.000377
flTime: 0.000377

tolower( 'D' );
flTime: 0.009572
flTime: 0.009492
flTime: 0.009444
Result: tolower_R performed 25.05 times faster than tolower.
max_R( 40, 50 );
flTime: 0.000377
flTime: 0.000377
flTime: 0.000377

max( 40, 50 );
flTime: 0.001623
flTime: 0.001672
flTime: 0.001585
Result: max_R performed 4.2 times faster than max.
min_R( 40, 50 );
flTime: 0.000377
flTime: 0.000377
flTime: 0.000377

min( 40, 50 );
flTime: 0.001596
flTime: 0.001567
flTime: 0.001564
Result: min_R performed 4.14 times faster than min.
random_R( 50 );
flTime: 0.000606
flTime: 0.000626
flTime: 0.000608

random( 50 );
flTime: 0.001708
flTime: 0.001689
flTime: 0.001799
Result: random_R performed 2.78 times faster than random.
clamp_R( 40, 50, 60 );
flTime: 0.000395
flTime: 0.000377
flTime: 0.000377

clamp( 40, 50, 60 );
flTime: 0.001761
flTime: 0.001702
flTime: 0.001714
Result: clamp_R performed 4.51 times faster than clamp.
--------------------------
LATE ADDITIONS
--------------------------

RANDOM_NUM( 25, 75 );
flTime: 0.000621
flTime: 0.000631
flTime: 0.000618

random_num( 25, 75 );
flTime: 0.002598
flTime: 0.002574
flTime: 0.002605
Result: RANDOM_NUM performed 4.16 times faster than random_num.
RANDOM_FLOAT( 25.5, 75.5 );
flTime: 0.000628
flTime: 0.000625
flTime: 0.000608

random_float( 25.5, 75.5 );
flTime: 0.002517
flTime: 0.002549
flTime: 0.002614
Result: RANDOM_FLOAT performed 4.13 times faster than random_float.
*CHAR_TO_DIGIT should only be used for a single digit.
new const g_szSeven[ ] = "Number 7";
CHAR_TO_DIGIT( g_szSeven[ 7 ] );
flTime: 0.000797
flTime: 0.000868
flTime: 0.000855

str_to_num( g_szSeven[ 7 ] );
flTime: 0.004960
flTime: 0.005031
flTime: 0.004981
Result: CHAR_TO_DIGIT performed 6.22 times faster than str_to_num.
*UNREG_FM avoids calling the unregister_forward() native on forwards that were already unregistered, which could occur in certain cases.
It does this by automatically clearing the passed handle; then quickly determines if the forward was not already unregistered by checking if the passed handle value is 0.

It has minimal impact in execution time of valid un-registration requests.

UNREG_FM( FM_UpdateClientData, pf_Already_Unregistered, false );
flTime: 0.000378
flTime: 0.000377
flTime: 0.000406

unregister_forward( FM_UpdateClientData, pf_Already_Unregistered, false );
flTime: 0.001887
flTime: 0.001805
flTime: 0.001801
Result: UNREG_FM performed 4.77 times faster than unregister_forward.
*Profiling results in this page are accurate and were obtained in
appropriate environment at similar conditions using the same notebook.

*Different computers may obtain lower or higher diffs. than the proportions herein displayed.

*Intel(R) Core(TM)2 Duo T6400 @ 2.00GHz is a Dual-Core processor from 2009.

* Multi-Core processors tend to obtain even higher diffs.
Attachments
runtime.inc.zip
(1.29 KiB) Downloaded 2 times

Who is online

Users browsing this forum: No registered users and 1 guest