Object add vs Array add 123 (v6)

Revision 6 of this benchmark created by shds86 on


Setup

var cCharDelimiter = String.fromCharCode(5)
    function Vertex(sheetId, cellId, wb){
        this.sheetId = sheetId;
        this.cellId = cellId;
        this.bbox = {c1:0,c2:0,r1:0,r2:0};
        this.isArea = Math.random() < 0.5 ? true : false;
        this.valid = true;
        this.nodeId = getVertexId(this.sheetId, this.cellId);
        this.wb = wb;
        this.cell = null;
        
        //вершина которую мы прошли и поставили в очередь обхода
        this.isBlack = false;
        
        //вершина которую мы прошли, но не поставили в очередь обхода. нужно для определения петель в графе.
        this.isGray = false;
    
    //если вершина входит в цикличный путь, то она помечается плохой и запоминается в списке плохих вершин.
    this.isBad = false;
    
    //masterEdges содержит ячейки, от которых зависит текущая ячейка
    this.masterEdges = {};
    
    //slaveEdges содержит ячейки, которые зависят от данной ячейки
    this.slaveEdges = {};
    
    this.refCount = 0;
    }
    Vertex.prototype = {
        
        constructor: Vertex,
        
        getBBox : function()
        {
                return this.bbox;
        },
        setFormula : function(sFormula, bAddToHistory, bAddNeedRecalc)
        {       },
        setRefError : function(wsId, cellId)
        {       },
        moveInner: function (bboxTo) 
      { },
        moveOuter: function (from, to, oFormulas) 
      { },
        //добавляем ведущую ячейку.
        addMasterEdge : function(node){
    
        this.masterEdges[node.nodeId] = node;
                this.refCount ++;
        },
    
        //добавляем зависимую(ведомую) ячейку.
        addSlaveEdge : function(node){
                this.slaveEdges[node.nodeId] = node;
                this.refCount ++;
        }
    }
    /*function getVertexId(sheetId, cellId){
        return sheetId + cCharDelimiter + cellId;
    }*/
    function getVertexId(sheetId, cellId){
      return "_"+new Date().getTime()+31415926;
    }

Test runner

Ready to run.

Testing in
TestOps/sec
o1
var o = [], o1, o2;
for(var i = 0; i < 10; i++){
 for(var j = 0; j < 10001; j++){
  o1 = new Vertex("20"+(20+i),String.fromCharCode(70+i)+j);
  o2 = new Vertex("20"+(20+i),String.fromCharCode(70+i)+(++j));
  o.push(o1);
  o.push(o2);
  o1.addMasterEdge(o2);
  o2.addSlaveEdge (o1);
 }
}
 
ready
o2
var o = [], o1, o2;
for(var i = 0; i < 10; i++){
 for(var j = 0; j < 10001; j++){
  o1 = new Vertex("20"+(20+i),(String.fromCharCode(70+i)+j).substring(0,4));
  o2 = new Vertex("20"+(20+i),(String.fromCharCode(70+i)+(++j)).substring(0,4));
  o.push(o1);
  o.push(o2);
  o1.addMasterEdge(o2);
  o2.addSlaveEdge (o1);
 }
}
ready
o3
var o = [], o1, o2;
for(var i = 0; i < 10; i++){
 for(var j = 0; j < 10001; j++){
  o1 = new Vertex("20"+(20+i),j);
  o2 = new Vertex("20"+(20+i),(++j));
  o.push(o1);
  o.push(o2);
  o1.addMasterEdge(o2);
  o2.addSlaveEdge (o1);
 }
}
 
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.

  • Revision 6: published by shds86 on