Skip to content

Instantly share code, notes, and snippets.

@Himenon
Created April 23, 2019 04:03
Show Gist options
  • Save Himenon/3bb8399f833b1e15d697cc8344b1024e to your computer and use it in GitHub Desktop.
Save Himenon/3bb8399f833b1e15d697cc8344b1024e to your computer and use it in GitHub Desktop.
const a = Array(100000).fill(Math.random());
const b = Array(100000).fill(Math.random());
const benchmark = (func, repeat) => {
const result = [];
Array(repeat)
.fill(1)
.map(() => {
const start = window.performance.now();
func();
const end = window.performance.now();
const time = end - start;
result.push(time);
});
const average = result.reduce((total, t) => total + t) / repeat;
console.table({ try: repeat, average });
};
benchmark(() => [...a, ...b], 1000);
benchmark(() => a.concat(b), 1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment