perf.html
author Oleksandr Gavenko <gavenkoa@gmail.com>
Tue, 09 Sep 2014 18:45:26 +0300
changeset 26 fba85224a8f0
parent 8 395195ae7daf
child 93 c2bf15c3b80b
permissions -rw-r--r--
Remove debug code.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     1
<!DOCTYPE html>
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     2
<html>
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     3
<head>
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     4
  <title>js perf</title>
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     5
  <meta name="viewport" content="width=device-width,initial-scale=1.0"/>
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     6
  <meta charset="utf-8"/>
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     7
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     8
  <script src="board.js"></script>
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     9
  <script src="perf.js"></script>
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    10
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    11
  <style>
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    12
    body {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    13
      width: 100%;
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    14
    }
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    15
    h1, div.area {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    16
      text-align: center;
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    17
      margin: 10px auto;
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    18
    }
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    19
    #board {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    20
      margin: 10px auto;
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    21
    }
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    22
    #board td {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    23
      width: 40px;
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    24
      height: 40px;
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    25
      border: 1px solid red;
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    26
      margin: 0;
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    27
      text-align: center;
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    28
    }
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    29
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    30
    .test {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    31
      border: 1px red dotted;
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    32
    }
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    33
    .report {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    34
      border: 1px green dotted;
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    35
    }
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    36
  </style>
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    37
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    38
</head>
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    39
<body>
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    40
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    41
  <table id="board">
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    42
    <tr>
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    43
      <td></td>
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    44
      <td></td>
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    45
      <td></td>
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    46
      <td></td>
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    47
    </tr>
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    48
    <tr>
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    49
      <td></td>
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    50
      <td></td>
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    51
      <td></td>
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    52
      <td></td>
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    53
    </tr>
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    54
    <tr>
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    55
      <td></td>
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    56
      <td></td>
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    57
      <td></td>
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    58
      <td></td>
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    59
    </tr>
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    60
    <tr>
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    61
      <td></td>
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    62
      <td></td>
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    63
      <td></td>
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    64
      <td></td>
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    65
    </tr>
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    66
  </table>
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    67
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    68
  <div class="test">
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    69
    <button>Array vs 2d Array vs Object vs this Object</button>
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    70
    <div class="report"></div>
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    71
  </div>
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    72
  
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    73
  <script>
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    74
    var boardDom = document.getElementById("board");
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    75
    var ui = {};
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    76
    ui.set = function(i, j, val) {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    77
      boardDom.querySelectorAll("tr")[i].querySelectorAll("td")[j].innerHTML = val;
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    78
    }
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    79
  </script>
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    80
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    81
  <script>
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    82
    /* var N = 1; */
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    83
    /* var N = 1000*1000; */
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    84
    var N = 1000*1000;
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    85
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    86
    function arrNew() {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    87
      return [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    88
    }
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    89
    function arrGet(brd, i, j) {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    90
      return brd[i*4+j];
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    91
    }
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    92
    function arrSet(brd, i, j, val) {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    93
      brd[i*4+j] = val;
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    94
    }
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    95
    function arrPrint(brd) {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    96
      for (var i = 0; i < 4; i++) {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    97
        for (var j = 0; j < 4; j++) {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    98
          ui.set(i, j, brd[i*4+j]);
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    99
        }
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   100
      }
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   101
    }
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   102
    function arrRotLeft(from, to) {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   103
      for (var i = 0; i < 4; i++) {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   104
        for (var j = 0; j < 3; j++) {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   105
          to[i*4+j+1] = from[i*4+j];
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   106
        }
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   107
        to[i*4] = from[i*4+3];
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   108
      }
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   109
    }
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   110
    function arrRotLeft_2(from, to) {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   111
      to[1] = from[0]; to[2] = from[1]; to[3] = from[2]; to[0] = from[3];
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   112
      to[4+1] = from[4+0]; to[4+2] = from[4+1]; to[4+3] = from[4+2]; to[4+0] = from[4+3];
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   113
      to[8+1] = from[8+0]; to[8+2] = from[8+1]; to[8+3] = from[8+2]; to[8+0] = from[8+3];
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   114
      to[12+1] = from[12+0]; to[12+2] = from[12+1]; to[12+3] = from[12+2]; to[12+0] = from[12+3];
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   115
    }
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   116
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   117
    var L = arrNew();
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   118
    L[2*4+3] = 5;
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   119
    for (var i = 0; i < 4; i++) {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   120
      arrSet(L, i, 3-i, i+1);
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   121
    }
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   122
    var R = arrNew();
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   123
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   124
    /* Example of plain performance calculation. */
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   125
    var tsFrom = new Date().getTime();
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   126
    for (var i = 0; i < N; i++) {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   127
      arrRotLeft(L, R);
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   128
      arrRotLeft(R, L);
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   129
    }
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   130
    var tsTo = new Date().getTime();
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   131
    arrPrint(L);
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   132
    console.log("arrRotLeft: %f ms, %d u/s", tsTo-tsFrom, 2*i/(tsTo - tsFrom)*1000);
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   133
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   134
    perf("arrRotLeft", function() {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   135
      arrRotLeft(this.L, this.R);
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   136
      arrRotLeft(this.R, this.L);
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   137
    }, N, {L: L, R: R});
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   138
    arrPrint(L);
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   139
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   140
    perf("arrRotLeft_2", function() {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   141
      arrRotLeft_2(this.L, this.R);
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   142
      arrRotLeft_2(this.R, this.L);
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   143
    }, N, {L: L, R: R});
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   144
    arrPrint(L);
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   145
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   146
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   147
    perf("BoardArr.prototype.copy|new", function() {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   148
      this.brd = this.brd.copy();
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   149
    }, N, {brd: new BoardArr()});
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   150
    perf("BoardArr.prototype.copy|from-to", function() {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   151
      this.from.copy(this.to);
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   152
    }, N, {from: new BoardArr(), to: new BoardArr()});
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   153
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   154
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   155
    perf("BoardArr2d.prototype.copy|new", function() {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   156
      this.brd = this.brd.copy();
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   157
    }, N, {brd: new BoardArr2d()});
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   158
    perf("BoardArr2d.prototype.copy|from-to", function() {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   159
      this.from.copy(this.to);
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   160
    }, N, {from: new BoardArr2d(), to: new BoardArr2d()});
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   161
    perf("BoardArr2d.prototype.shiftLeft_unrolled", function() {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   162
      this.from.shiftLeft_unrolled(this.to);
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   163
      var swap = this.from; this.from = this.to, this.to = swap;
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   164
    }, N, {from: new BoardArr2d(), to: new BoardArr2d()});
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   165
    perf("BoardArr2d.prototype.shiftLeft_mostly_unrolled", function() {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   166
      this.from.shiftLeft_mostly_unrolled(this.to);
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   167
      var swap = this.from; this.from = this.to, this.to = swap;
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   168
    }, N, {from: new BoardArr2d(), to: new BoardArr2d()});
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   169
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   170
    function arr2New() {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   171
      return [[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0]];
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   172
    }
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   173
    function arr2Get(brd, i, j) {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   174
      return brd[i][j];
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   175
    }
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   176
    function arr2Set(brd, i, j, val) {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   177
      brd[i][j] = val;
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   178
    }
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   179
    function arr2Print(brd) {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   180
      for (var i = 0; i < 4; i++) {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   181
        for (var j = 0; j < 4; j++) {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   182
          ui.set(i, j, brd[i][j]);
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   183
        }
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   184
      }
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   185
    }
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   186
    function arr2RotLeft(from, to) {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   187
      for (var i = 0; i < 4; i++) {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   188
        for (var j = 0; j < 3; j++) {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   189
          to[i][j+1] = from[i][j];
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   190
        }
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   191
        to[i][0] = from[i][3];
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   192
      }
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   193
    }
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   194
    function arr2RotLeft_2(from, to) {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   195
      to[0][1] = from[0][0]; to[0][2] = from[0][1]; to[0][3] = from[0][2]; to[0][0] = from[0][3];
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   196
      to[1][1] = from[1][0]; to[1][2] = from[1][1]; to[1][3] = from[1][2]; to[1][0] = from[1][3];
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   197
      to[2][1] = from[2][0]; to[2][2] = from[2][1]; to[2][3] = from[2][2]; to[2][0] = from[2][3];
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   198
      to[3][1] = from[3][0]; to[3][2] = from[3][1]; to[3][3] = from[3][2]; to[3][0] = from[3][3];
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   199
    }
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   200
    function arr2ShiftRight(from, to) {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   201
      for (var i = 0; i < 4; i++) {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   202
        if (from[i][2] == from[i][3]) {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   203
          to[i][3] = from[i][3] + 1;
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   204
          if (from[i][0] == from[i][1]) {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   205
            to[i][2] = from[i][1] + 1;
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   206
            to[i][1] = 0;
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   207
          } else {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   208
            to[i][2] = from[i][1];
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   209
            to[i][1] = from[i][0];
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   210
          }
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   211
          to[i][0] = 0;
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   212
        } else {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   213
          to[i][3] = from[i][3];
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   214
          if (from[i][1] == from[i][2]) {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   215
            to[i][2] = from[i][2] + 1;
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   216
            to[i][1] = from[i][0];
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   217
            to[i][0] = 0;
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   218
          } else {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   219
            to[i][2] = from[i][2];
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   220
            if (from[i][0] == from[i][1]) {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   221
              to[i][1] = from[i][1] + 1;
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   222
              to[i][0] = 0;
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   223
            } else {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   224
              to[i][1] = from[i][1];
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   225
              to[i][0] = from[i][0];
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   226
            }
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   227
          }
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   228
        }
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   229
      }
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   230
    }
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   231
    function arr2ShiftLeft(from, to) {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   232
      for (var i = 3; i >= 0; i--) {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   233
        if (from[i][0] == from[i][1]) {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   234
          to[i][0] = from[i][0] + 1;
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   235
          if (from[i][2] == from[i][3]) {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   236
            to[i][1] = from[i][2] + 1;
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   237
            to[i][2] = 0;
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   238
          } else {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   239
            to[i][1] = from[i][2];
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   240
            to[i][2] = from[i][3];
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   241
          }
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   242
          to[i][3] = 0;
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   243
        } else {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   244
          to[i][0] = from[i][0];
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   245
          if (from[i][1] == from[i][2]) {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   246
            to[i][1] = from[i][1] + 1;
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   247
            to[i][2] = from[i][3];
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   248
            to[i][3] = 0;
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   249
          } else {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   250
            to[i][1] = from[i][1];
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   251
            if (from[i][2] == from[i][3]) {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   252
              to[i][2] = from[i][2] + 1;
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   253
              to[i][3] = 0;
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   254
            } else {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   255
              to[i][2] = from[i][2];
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   256
              to[i][3] = from[i][3];
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   257
            }
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   258
          }
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   259
        }
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   260
      }
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   261
    }
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   262
    function arr2ShiftUp(from, to) {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   263
      for (var j = 3; j >= 0; j--) {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   264
        if (from[0][j] == from[1][j]) {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   265
          to[0][j] = from[0][j] + 1;
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   266
          if (from[2][j] == from[3][j]) {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   267
            to[1][j] = from[2][j] + 1;
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   268
            to[2][j] = 0;
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   269
          } else {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   270
            to[1][j] = from[2][j];
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   271
            to[2][j] = from[3][j];
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   272
          }
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   273
          to[3][j] = 0;
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   274
        } else {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   275
          to[0][j] = from[0][j];
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   276
          if (from[1][j] == from[2][j]) {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   277
            to[1][j] = from[1][j] + 1;
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   278
            to[2][j] = from[3][j];
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   279
            to[3][j] = 0;
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   280
          } else {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   281
            to[1][j] = from[1][j];
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   282
            if (from[2][j] == from[3][j]) {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   283
              to[2][j] = from[2][j] + 1;
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   284
              to[3][j] = 0;
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   285
            } else {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   286
              to[2][j] = from[2][j];
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   287
              to[3][j] = from[3][j];
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   288
            }
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   289
          }
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   290
        }
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   291
      }
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   292
    }
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   293
    function arr2ShiftDown(from, to) {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   294
      for (var j = 0; j < 4; j++) {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   295
        if (from[2][j] == from[3][j]) {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   296
          to[3][j] = from[3][j] + 1;
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   297
          if (from[0][j] == from[1][j]) {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   298
            to[2][j] = from[1][j] + 1;
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   299
            to[1][j] = 0;
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   300
          } else {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   301
            to[2][j] = from[1][j];
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   302
            to[1][j] = from[0][j];
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   303
          }
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   304
          to[0][j] = 0;
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   305
        } else {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   306
          to[3][j] = from[3][j];
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   307
          if (from[1][j] == from[2][j]) {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   308
            to[2][j] = from[2][j] + 1;
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   309
            to[1][j] = from[0][j];
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   310
            to[0][j] = 0;
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   311
          } else {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   312
            to[2][j] = from[2][j];
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   313
            if (from[0][j] == from[1][j]) {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   314
              to[1][j] = from[1][j] + 1;
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   315
              to[0][j] = 0;
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   316
            } else {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   317
              to[1][j] = from[1][j];
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   318
              to[0][j] = from[0][j];
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   319
            }
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   320
          }
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   321
        }
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   322
      }
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   323
    }
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   324
    var L = arr2New();
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   325
    L[2][3] = 5;
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   326
    for (var i = 0; i < 4; i++) {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   327
      arr2Set(L, i, 3-i, i+1);
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   328
    }
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   329
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   330
    var R = arr2New();
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   331
    var tsFrom = new Date().getTime();
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   332
    for (var i = 0; i < N; i++) {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   333
      arr2RotLeft(L, R);
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   334
      arr2RotLeft(R, L);
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   335
    }
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   336
    var tsTo = new Date().getTime();
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   337
    /* arr2Print(L); */
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   338
    console.log("arr2RotLeft: %f ms, %d u/s", tsTo-tsFrom, 2*i/(tsTo - tsFrom)*1000);
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   339
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   340
    var tsFrom = new Date().getTime();
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   341
    for (var i = 0; i < N; i++) {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   342
      arr2RotLeft_2(L, R);
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   343
      arr2RotLeft_2(R, L);
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   344
    }
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   345
    var tsTo = new Date().getTime();
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   346
    /* arr2Print(L); */
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   347
    console.log("arr2RotLeft_2: %f ms, %d u/s", tsTo-tsFrom, 2*i/(tsTo - tsFrom)*1000);
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   348
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   349
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   350
    var objMap = [["aa", "ab", "ac", "ad"], ["ba", "bb", "bc", "bd"], ["ca", "cb", "cc", "cd"], ["da", "db", "dc", "dd"]];
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   351
    function objNew() {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   352
      return { aa: 0, ab: 0, ac: 0, ad: 0,
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   353
               ba: 0, bb: 0, bc: 0, bd: 0,
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   354
               ca: 0, cb: 0, cc: 0, cd: 0,
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   355
               da: 0, db: 0, dc: 0, dd: 0 };
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   356
    }
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   357
    function objGet(brd, i, j) {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   358
      return brd[objMap[i][j]];
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   359
    }
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   360
    function objSet(brd, i, j, val) {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   361
      brd[objMap[i][j]] = val;
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   362
    }
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   363
    function objPrint(brd) {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   364
      ui.set(0, 0, brd.aa); ui.set(0, 1, brd.ab); ui.set(0, 2, brd.ac); ui.set(0, 3, brd.ad);
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   365
      ui.set(1, 0, brd.ba); ui.set(1, 1, brd.bb); ui.set(1, 2, brd.bc); ui.set(1, 3, brd.bd);
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   366
      ui.set(2, 0, brd.ca); ui.set(2, 1, brd.cb); ui.set(2, 2, brd.cc); ui.set(2, 3, brd.cd);
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   367
      ui.set(3, 0, brd.da); ui.set(3, 1, brd.db); ui.set(3, 2, brd.dc); ui.set(3, 3, brd.dd);
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   368
    }
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   369
    function objRotLeft(from, to) {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   370
      to.ab = from.aa; to.ac = from.ab; to.ad = from.ac; to.aa = from.ad;
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   371
      to.bb = from.ba; to.bc = from.bb; to.bd = from.bc; to.ba = from.bd;
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   372
      to.cb = from.ca; to.cc = from.cb; to.cd = from.cc; to.ca = from.cd;
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   373
      to.db = from.da; to.dc = from.db; to.dd = from.dc; to.da = from.dd;
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   374
    }
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   375
    function objRotLeft_2(from, to) {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   376
      to["ab"] = from["aa"]; to["ac"] = from["ab"]; to["ad"] = from["ac"]; to["aa"] = from["ad"];
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   377
      to["bb"] = from["ba"]; to["bc"] = from["bb"]; to["bd"] = from["bc"]; to["ba"] = from["bd"];
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   378
      to["cb"] = from["ca"]; to["cc"] = from["cb"]; to["cd"] = from["cc"]; to["ca"] = from["cd"];
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   379
      to["db"] = from["da"]; to["dc"] = from["db"]; to["dd"] = from["dc"]; to["da"] = from["dd"];
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   380
    }
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   381
    var L = objNew();
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   382
    L.cd = 5;
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   383
    for (var i = 0; i < 4; i++) {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   384
      objSet(L, i, 3-i, i+1);
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   385
    }
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   386
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   387
    var R = objNew();
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   388
    var tsFrom = new Date().getTime();
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   389
    for (var i = 0; i < N; i++) {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   390
      objRotLeft(L, R);
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   391
      objRotLeft(R, L);
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   392
    }
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   393
    var tsTo = new Date().getTime();
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   394
    objPrint(L);
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   395
    console.log("objRotLeft: %f ms, %d u/s", tsTo-tsFrom, 2*i/(tsTo - tsFrom)*1000);
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   396
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   397
    var tsFrom = new Date().getTime();
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   398
    for (var i = 0; i < N; i++) {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   399
      objRotLeft_2(L, R);
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   400
      objRotLeft_2(R, L);
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   401
    }
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   402
    var tsTo = new Date().getTime();
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   403
    objPrint(L);
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   404
    console.log("objRotLeft_2: %f ms, %d u/s", tsTo-tsFrom, 2*i/(tsTo - tsFrom)*1000);
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   405
  </script>
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   406
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   407
  <script>
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   408
    /* console.log(Array.prototype.map.call(document.querySelectorAll("button"), function(x){return x;})); */
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   409
    Array.prototype.forEach.call(document.querySelectorAll("button"), function(btn) {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   410
      console.log(btn)
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   411
    });
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   412
  </script>
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   413
</body>
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   414
</html>