delete_duration_test
Module compares productivity of or
- deleting of object's property
- deleting of array's element.
by means of different sets (script-lets) of commands.
Tests algorithm :
For objects: there are object and it's identical clone: o
and o1
,
periodically in cycle some property of object o
is deleted
and than is restored again from clone. Operation repeats multiple
times and the time of operation is measured.
The summed time of 1000000 deletions is measured for each deleting methods. Methods used for deleting and reassigning an object's property
-
delete o[pName]; o[pName] = o1[pName];
-
Object.defineProperty(o, pName, {enumerable: false}); Object.defineProperty(o, pName, {enumerable: true});
-
o[pName] = undefined; o[pName] = o1[pName];
Methods of deleting array's element with index iT
-
arr.splice(iT,1);
-
arr.slice(0,iT).concat( arr.slice(iT + 1) );
-
arr.filter(function(el,i){return i!==iT});
-
var a = []; for(var i = 0;i < iT;i++){ a.push(arr[i]); } for(i = iT + 1;i < arr.length;i++){ a.push(arr[i]); }
Install module:
In home directory cd go/in/proj/directory
npm install deletedurationtest --save-prod
Usage inside user module or in node REPL
module's import inside user's module:
var t = require('./deletedurationtest.js') ||
require( './');
A. To run object's property deletion tests type:
t.tr().runTest();
B. tests array's element deletion:
t.tr().runForArr();
To carry out test on another framework, for example, inside Chrome console.
- open Google Chrome
- press F12
- Open main module js-file in text editor, selectAll and copy content as one chunk of codes
- Paste clipboard data inside Chrome console.
- Press Enter. Don't pay attention on diagnostic regarding 'exports is not defined'.
- Then type inside console commands as follows:
var tr = deleteDurationTest(); // case sensitive typing!!
tr.runTest(); // for object's property deletion testSplice or
tr.runForArr(); // for array's element deletion testSplice