-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Open
Labels
Description
(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.