I did a benchmark test for the map function.
the native map method slower than for loop 6x.
var result = new $Array();
|
var accumulator = new InternalArray(length);
|
if (%DebugCallbackSupportsStepping(f)) {
|
for (var i = 0; i < length; i++) {
|
if (i in array) {
|
var element = array[i];
|
// Prepare break slots for debugger step in.
|
%DebugPrepareStepInIfStepping(f);
|
accumulator[i] = %_CallFunction(receiver, element, i, array, f);
|
}
|
}
|
} else {
|
// This is a duplicate of the previous loop sans debug stepping.
|
for (var i = 0; i < length; i++) {
|
if (i in array) {
|
var element = array[i];
|
accumulator[i] = %_CallFunction(receiver, element, i, array, f);
|
}
|
}
|
// End of duplicate.
|
}
|
%MoveArrayContents(accumulator, result);
|
| return result; |
There are two strange places:
1. if (i in array) {
2. %MoveArrayContents(accumulator, result);
Could some guys tell me the reason? I love the sugar, but the performance hurt me.