jazzraill 3 Posted July 5, 2017 Greetings, I'm currently working on a code that runs for each spawned entity on the map so it should be the quickest. However I'm stuck between two desicions: First one uses less lines of code, but more private variables : switch _cond1 do { case 1: { _y = 1;_z = 3; }; case 2: { _y = 2;_z = 4; }; }; switch _cond2 do { case 1: { _c = 1; }; case 2: { _c = 3; }; }; _n = (_y*_z)+_c; The second one uses more lines of code, but no variables at all: _cond1,_cond2 call { if (_cond1 isEqualTo 1) exitWith { _cond2 call { if (_cond2 isEqualTo 1) exitWith {4}; }; _cond2) call { if (_cond2 isEqualTo 2) exitWith {6}; }; }; }; _cond1,_cond2 call { if (_cond1 isEqualTo 2) exitWith { _cond2 call { if (_cond2 isEqualTo 1) exitWith {7}; }; _cond2 call { if (_cond2 isEqualTo 2) exitWith {9}; }; }; }; Share this post Link to post Share on other sites
Boerstil 8 Posted July 5, 2017 https://community.bistudio.com/wiki/BIS_fnc_codePerformance 1 Share this post Link to post Share on other sites
jazzraill 3 Posted July 5, 2017 16 minutes ago, Boerstil said: https://community.bistudio.com/wiki/BIS_fnc_codePerformance thanks for the reply! for anyone else wondering, the second code was almos 1.5 times faster .. (I'm also coding this on a core 2 duo so results may differ) Share this post Link to post Share on other sites
R3vo 2650 Posted July 5, 2017 9 hours ago, jazzraill said: thanks for the reply! for anyone else wondering, the second code was almos 1.5 times faster .. (I'm also coding this on a core 2 duo so results may differ) You'll fine some useful information here https://community.bistudio.com/wiki/Code_Optimisation#How_to_test_and_gain_this_information_yourself.3F Share this post Link to post Share on other sites
killzone_kid 1325 Posted July 5, 2017 19 hours ago, jazzraill said: thanks for the reply! for anyone else wondering, the second code was almos 1.5 times faster .. (I'm also coding this on a core 2 duo so results may differ) interesting, code 2 contains a bunch of errors which should prevent it from compiling let alone running Share this post Link to post Share on other sites
Grumpy Old Man 3511 Posted July 6, 2017 What KK said, got some syntax errors in there. if then / if exitWith will always be faster than switch. exitWith in combination with call is a bit faster. Cheers Share this post Link to post Share on other sites
pierremgi 4440 Posted July 7, 2017 The "no variable at all" is just excessive. But the code has no sense and the comparison is about some calculations vs some fixed values. No benchmark needed for that. Share this post Link to post Share on other sites