Last active
November 6, 2019 09:18
Revisions
-
warpech revised this gist
Nov 6, 2019 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -32,7 +32,7 @@ } /* Conclusion (Chrome & FF): Naive arrays are faster for reads than preallocated, because naive are PACKED and preallocated are HOLEY See: https://github.com/babel/babel/issues/6233 -
warpech revised this gist
Nov 6, 2019 . 1 changed file with 0 additions and 4 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -48,10 +48,6 @@ } }); suite.on("cycle", function (evt) { console.log(" - " + evt.target); }); -
warpech revised this gist
Nov 6, 2019 . 1 changed file with 4 additions and 2 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -26,8 +26,9 @@ suite.add("naive", function () { // naive let result; for(let i = 0; i < length; i++) { result = naiveArray[i]; } /* @@ -41,8 +42,9 @@ suite.add("preallocated", function () { // preallocated let result; for(let i = 0; i < length; i++) { result = preallocatedArray[i]; } }); -
warpech revised this gist
Nov 6, 2019 . 2 changed files with 10 additions and 5 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,7 @@ <html> <head> <meta charset="utf-8"/> <title>Array read #jsbench #jsperf</title> <script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script> <script src="./suite.js"></script> </head> This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -29,6 +29,14 @@ for(let i = 0; i < length; i++) { naiveArray.push(true); } /* Conclusion: Naive arrays are faster for reads than preallocated, because naive are PACKED and preallocated are HOLEY See: https://github.com/babel/babel/issues/6233 https://v8.dev/blog/elements-kinds */ }); suite.add("preallocated", function () { @@ -39,10 +47,7 @@ }); suite.add("", function () { }); suite.on("cycle", function (evt) { @@ -61,7 +66,7 @@ }); }); console.log("Array read #jsbench #jsperf"); console.log(new Array(30).join("-")); suite.run(); }); -
warpech created this gist
Nov 6, 2019 .There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,13 @@ <!DOCTYPE html> <html> <head> <meta charset="utf-8"/> <title>Array read</title> <script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script> <script src="./suite.js"></script> </head> <body> <h1>Open the console to view the results</h1> <h2><code>cmd + alt + j</code> or <code>ctrl + alt + j</code></h2> </body> </html> This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,67 @@ "use strict"; (function (factory) { if (typeof Benchmark !== "undefined") { factory(Benchmark); } else { factory(require("benchmark")); } })(function (Benchmark) { var suite = new Benchmark.Suite; Benchmark.prototype.setup = function () { const length = 10000; const naiveArray = []; for(let i = 0; i < length; i++) { naiveArray.push(true); } const preallocatedArray = new Array(length); for(let i = 0; i < length; i++) { preallocatedArray[i] = true; } }; suite.add("naive", function () { // naive for(let i = 0; i < length; i++) { naiveArray.push(true); } }); suite.add("preallocated", function () { // preallocated for(let i = 0; i < length; i++) { preallocatedArray[i] = true; } }); suite.add("", function () { /* Conclusion: Naive arrays are faster for reads than preallocated, because naive are PACKED and preallocated are HOLEY */ }); suite.on("cycle", function (evt) { console.log(" - " + evt.target); }); suite.on("complete", function (evt) { console.log(new Array(30).join("-")); var results = evt.currentTarget.sort(function (a, b) { return b.hz - a.hz; }); results.forEach(function (item) { console.log((idx + 1) + ". " + item); }); }); console.log("Array read"); console.log(new Array(30).join("-")); suite.run(); });