Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

time complexity javascript

const benchmarkMap = size => {
  console.time('benchmarkMap');
  var map = new Map();
  for (var i = 0; i < size; i++) map.set(i, i);
  for (var i = 0; i < size; i++) var x = map.get(i);
  console.timeEnd('benchmarkMap');
}

const benchmarkObj = size => {
  console.time('benchmarkObj');
  var obj = {};
  for (var i = 0; i < size; i++) obj[i] = i;
  for (var i = 0; i < size; i++) var x = obj[i];
  console.timeEnd('benchmarkObj');
}

var size = 1000000;

benchmarkMap(size);
benchmarkObj(size);


//OUTPUT
benchmarkMap: 189.120ms
benchmarkObj: 44.214ms

benchmarkMap: 200.817ms
benchmarkObj: 38.963ms

benchmarkMap: 187.968ms
benchmarkObj: 41.633ms

benchmarkMap: 186.533ms
benchmarkObj: 35.850ms

benchmarkMap: 187.339ms
benchmarkObj: 44.515ms
Comment

PREVIOUS NEXT
Code Example
Javascript :: apply css to iframe content javascript 
Javascript :: link reload page react 
Javascript :: use jq to update json file 
Javascript :: redux toolkit with redux persist 
Javascript :: how to route react from laravel 
Javascript :: convert a string to number in javascript 
Javascript :: check href javascript 
Javascript :: filter parameters in javascript 
Javascript :: not disabled jquery 
Javascript :: js for loops 
Javascript :: Orderby on multiple columns using typeorm 
Javascript :: first letter uppercase in jquery 
Javascript :: commander js 
Javascript :: js click change img 
Javascript :: js time function 
Javascript :: how to flat an array in javascript iteratively 
Javascript :: javascript min max array 
Javascript :: create dynamic element in javascript 
Javascript :: js function 
Javascript :: javascript remove object key 
Javascript :: http delete angular 
Javascript :: scroll down or up event listener 
Javascript :: jquery get element tag 
Javascript :: api.fetch saga 
Javascript :: how to crash with js 
Javascript :: Get element id by name 
Javascript :: moment format dd.mm.yyyy 
Javascript :: spread operator in javascript 
Javascript :: Disabling right click using Javascript 
Javascript :: this.handler.handle is not a function 
ADD CONTENT
Topic
Content
Source link
Name
7+1 =