January 2018
Intermediate to advanced
332 pages
7h 36m
English
We will have a similar setup for Maps and Objects in a file called maps-obj.js, which will give us something like the following:
var Benchmark = require("benchmark");var suite = new Benchmark.Suite();var map = new Map();var obj = {};for(var i=0; i < 100; i++) { map.set(i, i); obj[i] = i;}suite .add("Object #get", function(){ obj[19]; }) .add("Map #get", function(){ map.get(19); }) // .add("Object #delete", function(){ delete obj[99]; }) .add("Map #delete", function(){ map.delete(99); }) .add("Object #length", function(){ Object.keys(obj).length; }) .add("Map #size", function(){ map.size; }) .on("cycle", function(e) { console.log("" + e.target); }) .run();
Now, to run this suite, run the following command on a Terminal:
Read now
Unlock full access