I did a benchmark test for the map function.

http://jsperf.com/jacksontianmyforpkmap

the native map method slower than for loop 6x.

And view the v8 source 
code, http://code.google.com/p/v8/source/browse/trunk/src/array.js#1235

  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.

-- 
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users

Reply via email to