Skip to content

Perf : filling the array is taking time #5386

@akroshg

Description

@akroshg
(function() {
  print('Array fill with increment of 2')
  var start = new Date();
  let maxSize = 2**25;
  let arr = new Array(maxSize);
  for (i = 0; i < maxSize; i += 2) {
      arr[i] = i;
  }

  print('time spent : ' + ((new Date()) - start));
})();

(function() {
  print('Array fill with increment of 512')
  var start = new Date();
  let maxSize = 2**25;
  let arr = new Array(maxSize);
  for (i = 0; i < maxSize; i += 512) {
      arr[i] = i;
  }

  print('time spent : ' + ((new Date()) - start));
})();

Output:

Array fill with increment of 2
time spent : 369
Array fill with increment of 512
time spent : 4196

This is strange - with 512 increment we should be filling less items to the array and we should be spending less time.
I suspect this may be due to more number of sparse array segment. I haven't created trace to support my theory.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions