@bytesnz

Jack Farley, Web Application Engineer

Nfa + Nfb or N(f+fa+fb)

Someone asked on gitter:
Hey guys, could u tell me what is better ( performance ):
1) Run multiple functions with looping throught array ?

1
2
function a( arr ) { _.map( arr, ( ar ) => { /* doing stuff related to func a */ } ); }
function b( arr ) { _.map( arr, ( ar ) => { /* doing stuff related to func b */ } ); }`

2) Loop array and run functions inside ?

1
2
3
function a( ar ) { /* doing stuff related to func a with array element */ }
function b( ar ) { /* doing stuff related to func b with array element */ }
_.map( arr, ( ar ) => { a( ar ); b( ar ); } );

So I decided to put a little test on jsperf together:
http://jsperf.com/run-array-x-times-vs-call-n-x-times/3

The results were 2 was faster (though inlining the functionality in the function calls [ => Nf] was better)