diff --git a/_includes/footer.liquid b/_includes/footer.liquid index bd89a7a..8ba84cd 100644 --- a/_includes/footer.liquid +++ b/_includes/footer.liquid @@ -1,6 +1,6 @@ diff --git a/_posts/2024/2024-05-10-fast-shallow-array-cloning-in-javascript/2024-05-10-fast-shallow-array-cloning-in-javascript.html b/_posts/2024/2024-05-10-fast-shallow-array-cloning-in-javascript/2024-05-10-fast-shallow-array-cloning-in-javascript.html index eb373f2..0bbf6ec 100644 --- a/_posts/2024/2024-05-10-fast-shallow-array-cloning-in-javascript/2024-05-10-fast-shallow-array-cloning-in-javascript.html +++ b/_posts/2024/2024-05-10-fast-shallow-array-cloning-in-javascript/2024-05-10-fast-shallow-array-cloning-in-javascript.html @@ -9,12 +9,12 @@ tags: ["JavaScript", "Array", "Shallow-Clone", "Clone", "Duplicate", "ECMAScript
Searching for an answer, I stumbled on this StackOverflow question. And as usual, almost all of the answers are simply regurgitated content with nothing to back it up. So with nothing else to do on a weekend, I threw my entire knowlEdge 124.0.2478.97 at the problem, wrote a benchmarking "tool", wrote several ways to do the same, and I think I found it.
Copyright 2024 Michael Fabian 'Xaymar' Dirks
I'm not a fan of services like JSPerf or JSBench, so I wrote a generalized JavaScript benchmark. Many of them rely on third-party libraries, which tend to include to rely on more third-party libraries, and when something breaks you never know why or when it'll be fixed. So instead I wrote my own generic benchmarking function using only standard JavaScript, compatible with NodeJS and common Browsers:
+I'm not a fan of services like JSPerf or JSBench, as many of them tend to rely on third-party libraries and include permanently running code on the side. And when something breaks you never know why or when it'll be fixed, resulting in delays that really shouldn't be necessary. So instead I wrote my own generic benchmarking function using only standard JavaScript, compatible with NodeJS and common Browsers:
{% capture "code" %}{% include_relative benchTime.mjs %}{% endcapture %}{{ code | escape }}
@@ -30,7 +30,7 @@ tags: ["JavaScript", "Array", "Shallow-Clone", "Clone", "Duplicate", "ECMAScript
Now that we have everything, we just need to run the test, and even you can do it in your Browsers' Developer Console. Just paste this in: const { default: asc } = await import("./arrayShallowClone.mjs"); for (let e of [256, 2048, 16384, 131072, 1048576]){ console.log(e); asc(e); };, hit enter/return and it should start measuring. For my own sanity, I limited myself to NodeJS V8, Firefox SpiderMonkey and Chromium V8 only.
This is practically insanity, but hey - why not test it anyway. This is effectively a repeat of the previous block, but the numbers are even smaller. In NodeJS the fastest way is still array.slice(), in Edge it is Object.assign([], array), and Firefox is still cheating.
This is practically insanity, but hey - why not test it anyway. It's effectively a repeat of the previous block, but the numbers are even smaller. In NodeJS the fastest way is still array.slice(), in Edge it is Object.assign([], array), and Firefox is still cheating.