Skip to content

Instantly share code, notes, and snippets.

@cevek
Last active November 26, 2019 07:10
Show Gist options
  • Save cevek/42aba5bab7438f4cf0892efb3754bf0a to your computer and use it in GitHub Desktop.
Save cevek/42aba5bab7438f4cf0892efb3754bf0a to your computer and use it in GitHub Desktop.
function prepare(n) {
const arr = [];
for (let i = 0; i < n; i++) {
arr[i] = {a: i % 2 === 0 ? -i : i, b: {h: {x: i}, c: {i: i, d: {e: {e: {u: {x: i}}}}}}};
}
shuffleArray(arr);
return arr;
}
function shuffleArray(array) {
for (var i = array.length - 1; i > 0; i--) {
var j = Math.floor(Math.random() * (i + 1));
var temp = array[i];
array[i] = array[j];
array[j] = temp;
}
}
function foo(arr) {
let s = 0;
for (let i = 0; i < arr.length; i++) {
s += arr[i].a;
}
return s;
}
const arr = prepare(1e7);
console.time('perf');
let x = foo(arr);
console.timeEnd('perf');
console.log(process.memoryUsage(), x, arr);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment