b51053d89e
In the process: - add volatile types for FastJSArray and remove the length_fast accessor from JSArray with the application of more rigorous typing. - add micro benchmarks for testing all the interesting slice cases Also update a few assorted places in .tq code to make them more idiomatic. The original version of this patch had an overly agressive assert that has been loosened. TBR=jgruber@chromium.org Change-Id: I56870862f4b124d1b38372daa326182a526c874c Reviewed-on: https://chromium-review.googlesource.com/c/1291375 Reviewed-by: Daniel Clifford <danno@chromium.org> Commit-Queue: Daniel Clifford <danno@chromium.org> Cr-Commit-Position: refs/heads/master@{#56829}
84 lines
2.6 KiB
JavaScript
84 lines
2.6 KiB
JavaScript
// Copyright 2018 the V8 project authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
const kIterations = 1000000;
|
|
const kIterationShort = 10000;
|
|
const kArraySize = 64;
|
|
|
|
let smi_array = [];
|
|
for (let i = 0; i < kArraySize; ++i) smi_array[i] = Math.floor(Math.random() * 100);
|
|
|
|
let start = performance.now();
|
|
for (let x = 0; x < kIterations; ++x) {
|
|
smi_array.slice(0);
|
|
}
|
|
let stop = performance.now();
|
|
print("smi_array copy: " + (Math.floor((stop - start)*10)/10) + " ms");
|
|
|
|
start = performance.now();
|
|
for (let x = 0; x < kIterations; ++x) {
|
|
smi_array.slice(x % kArraySize);
|
|
}
|
|
stop = performance.now();
|
|
print("smi_array: " + (Math.floor((stop - start)*10)/10) + " ms");
|
|
|
|
let double_array = [];
|
|
for (let i = 0; i < kArraySize; ++i) double_array[i] = Math.random() * 100;
|
|
start = performance.now();
|
|
for (let x = 0; x < kIterations; ++x) {
|
|
double_array.slice(x % kArraySize);
|
|
}
|
|
stop = performance.now();
|
|
print("double_array: " + (Math.floor((stop - start)*10)/10) + " ms");
|
|
|
|
let object_array = [];
|
|
for (let i = 0; i < kArraySize; ++i) object_array[i] = new Object();
|
|
start = performance.now();
|
|
for (let x = 0; x < kIterations; ++x) {
|
|
object_array.slice(x % kArraySize);
|
|
}
|
|
stop = performance.now();
|
|
print("object_array: " + (Math.floor((stop - start)*10)/10) + " ms");
|
|
|
|
let dictionary_array = [];
|
|
for (let i = 0; i < kArraySize; ++i) dictionary_array[i] = new Object();
|
|
dictionary_array[100000] = new Object();
|
|
start = performance.now();
|
|
for (let x = 0; x < kIterationShort; ++x) {
|
|
dictionary_array.slice(x % kArraySize);
|
|
}
|
|
stop = performance.now();
|
|
print("dictionary: " + (Math.floor((stop - start)*10)/10) + " ms");
|
|
|
|
let arguments_array;
|
|
function sloppy() {
|
|
arguments_array = arguments;
|
|
}
|
|
sloppy.apply(null, smi_array);
|
|
start = performance.now();
|
|
for (let x = 0; x < kIterations; ++x) {
|
|
let r = Array.prototype.slice.call(arguments_array, x % kArraySize);
|
|
}
|
|
stop = performance.now();
|
|
print("arguments_array (sloppy): " + (Math.floor((stop - start)*10)/10) + " ms");
|
|
|
|
function sloppy2 (a) {
|
|
arguments_array = arguments;
|
|
}
|
|
sloppy2.apply(null, smi_array);
|
|
start = performance.now();
|
|
for (let x = 0; x < kIterations; ++x) {
|
|
Array.prototype.slice.call(arguments_array, x % kArraySize);
|
|
}
|
|
stop = performance.now();
|
|
print("arguments_array (fast aliased): " + (Math.floor((stop - start)*10)/10) + " ms");
|
|
|
|
delete arguments_array[5];
|
|
start = performance.now();
|
|
for (let x = 0; x < kIterationShort; ++x) {
|
|
Array.prototype.slice.call(arguments_array, x % kArraySize);
|
|
}
|
|
stop = performance.now();
|
|
print("arguments_array (slow aliased): " + (Math.floor((stop - start)*10)/10) + " ms");
|