BIS fnc codePerformance: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (note formate)
m (Text replacement - "BIS fnc " to "BIS_fnc_")
(48 intermediate revisions by 7 users not shown)
Line 1: Line 1:
{{Function|= Comments
{{RV|type=function
____________________________________________________________________________________________


| arma3|= Game name
|game1= arma3
|version1= 0.50


|0.50|= Game version
|gr1= Diagnostic
____________________________________________________________________________________________


| Measures how much time it takes to execute given expression. Results may vary based on overall performance; use this function to compare alternative scripting approaches rather than to measure specific values.
|descr= [[File:BIS_fnc_codePerformance.png|300px|right]]
Measures how much time it takes to execute given expression.
Results may vary based on overall performance; use this function to compare alternative scripting approaches rather than to measure specific values.
Upon function execution, window with results is opened. The user then has a choice to copy the result into clipboard or not.<br>
This function is using [[diag_codePerformance]] command.


In Arma 3, window with results is opened afterwards.
{{Feature|informative|Use [[toString]] to stringify [[Code]], as [[str]] adds curly braces - See {{Link|#Example 2}}.}}


'''NOTE:''' For best results restart your client before conducting tests. This function uses [[diag_tickTime]] which loses its precision the longer the client runs from restart.
|s1= [expression, arguments, cycles, display] call [[BIS_fnc_codePerformance]]


[[File:BIS fnc codePerformance.png|300px]]
|p1= expression: [[String]] - tested expression
|= Description
____________________________________________________________________________________________


| [expression([[String]]),Any([parameters]),cycles([[Number]])] call BIS_fnc_codePerformance; |= Syntax
|p2= arguments: [[Anything]] - (Optional, default []) arguments to pass into the code


|p1= '''expression''': [[String]] - tested expression |=
|p3= cycles: [[Number]] - (Optional, default 10000) number of wanted cycles
|p2= '''Any''' (Optional): Param(s) - passed into code (default: []) |=
|p3= '''cycles''' (Optional): [[Number]] - Number of cycles (default: 10000) |=


| [[Nothing]] |= Return value
|p4= display: [[Display]] - (Optional, default <sqf inline>findDisplay 46</sqf>) display in which the message window with results will be opened. Use [[displayNull]] to disable the window
____________________________________________________________________________________________
 
 
|r1= [[Number]] - Average execution time of the expression
|x1= <code>testArray = [];
 
["testArray = testArray + [1];"] [[call]] [[BIS_fnc_codePerformance]];
|x1= <sqf>
// compare three methods of adding elements into array
testArray = [];
["testArray = testArray + [1]"] call BIS_fnc_codePerformance;
testArray = [];
testArray = [];
["testArray [[set]] <nowiki>[</nowiki>[[count]] testArray,1];"] [[call]] [[BIS_fnc_codePerformance]];
["testArray set [count testArray, 1]"] call BIS_fnc_codePerformance;
</code>
testArray = [];
Compare two methods of adding elements into array|=
["testArray pushBack 1"] call BIS_fnc_codePerformance;
</sqf>


____________________________________________________________________________________________
|x2= <sqf>[toString { hint "Hello there" }] call BIS_fnc_codePerformance;</sqf>
 
| |= See also


|seealso= [[diag_codePerformance]]
}}
}}
<h3 style="display:none">Notes</h3>
<dl class="command_description">
<!-- Note Section BEGIN -->
<dd class="notedate">Posted on Mar 31, 2014 - 11:09
<dt class="note">'''[[User:ffur2007slx2_5|ffur2007slx2_5]]'''<dd class="note">
(ArmA3 1.14) Please always take advantage of the second and third parameters when running code on [[BIS_fnc_codePerformance]]. And it is not suggested to use reserved variables under scheduled environment. E.g.
<code>['
    [ { a = _this } ] [[spawn]] {
        [[private]] "_code";
        _code = [_this, 0, {}, [{}]] [[call]] [[BIS_fnc_param]];
        { _x [[call]] _code; } [[forEach]] [[allUnits]];
    };
'] [[call]] [[BIS_fnc_codePerformance]];</code>
There will be a great latency until GUI being displayed, never do like that, on the contrary, we should:
<code>['
    {
        [[private]] "_code";
        _code = [_this, 0, {}, [{}]] [[call]] [[BIS_fnc_param]];
        { _x [[call]] _code; } [[forEach]] [[allUnits]];
    }'
, [ {a = _this } ], 1000] [[call]] [[BIS_fnc_codePerformance]];</code>
As for the third parameter, only run the code with desired loop and not always 1000 times like the default set:
<code>
[‘
a = 0; b = [[true]];
[[for]] [{_i = 0},{_i < 10 && b},{_i = _i + 1}] [[do]] {
  a = a + 1;
  [[if]] (a >= 7) [[then]] {b = [[false]]};
};’
,[],1000] [[call]] [[BIS_fnc_codePerformance]];
//Sometimes such 1000 loops will freeze the game directly.
</code>
So separating all three parameters and using them wisely are recommended.
<!-- Note Section END -->
</dl>
<h3 style="display:none">Bottom Section</h3>
[[Category:Function Group: Debug|{{uc:codePerformance}}]]
[[Category:Functions|{{uc:codePerformance}}]]
[[Category:{{Name|tkoh}}: Functions|{{uc:codePerformance}}]]
[[Category:{{Name|arma3}}: Functions|{{uc:codePerformance}}]]

Revision as of 12:15, 27 July 2022

Hover & click on the images for description

Description

Description:
BIS fnc codePerformance.png

Measures how much time it takes to execute given expression. Results may vary based on overall performance; use this function to compare alternative scripting approaches rather than to measure specific values. Upon function execution, window with results is opened. The user then has a choice to copy the result into clipboard or not.
This function is using diag_codePerformance command.

Use toString to stringify Code, as str adds curly braces - See Example 2.
Execution:
call
Groups:
Diagnostic

Syntax

Syntax:
[expression, arguments, cycles, display] call BIS_fnc_codePerformance
Parameters:
expression: String - tested expression
arguments: Anything - (Optional, default []) arguments to pass into the code
cycles: Number - (Optional, default 10000) number of wanted cycles
display: Display - (Optional, default findDisplay 46) display in which the message window with results will be opened. Use displayNull to disable the window
Return Value:
Number - Average execution time of the expression

Examples

Example 1:
// compare three methods of adding elements into array testArray = []; ["testArray = testArray + [1]"] call BIS_fnc_codePerformance; testArray = []; ["testArray set [count testArray, 1]"] call BIS_fnc_codePerformance; testArray = []; ["testArray pushBack 1"] call BIS_fnc_codePerformance;
Example 2:
[toString { hint "Hello there" }] call BIS_fnc_codePerformance;

Additional Information

See also:
diag_codePerformance

Notes

Report bugs on the Feedback Tracker and/or discuss them on the Arma Discord or on the Forums.
Only post proven facts here! Add Note