perf.html
author Oleksandr Gavenko <gavenkoa@gmail.com>
Sun, 07 Aug 2016 23:23:15 +0300
changeset 188 754796e567ab
parent 93 c2bf15c3b80b
permissions -rw-r--r--
Rename function.
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 arrPrint(brd) {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    87
      for (var i = 0; i < 4; i++) {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    88
        for (var j = 0; j < 4; j++) {
93
c2bf15c3b80b Add some BoardObj routines.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 8
diff changeset
    89
          ui.set(i, j, brd[i][j]);
8
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    90
        }
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
    }
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    93
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    94
    /* Example of plain performance calculation. */
93
c2bf15c3b80b Add some BoardObj routines.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 8
diff changeset
    95
    // var tsFrom = new Date().getTime();
c2bf15c3b80b Add some BoardObj routines.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 8
diff changeset
    96
    // var i;
c2bf15c3b80b Add some BoardObj routines.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 8
diff changeset
    97
    // (function() {
c2bf15c3b80b Add some BoardObj routines.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 8
diff changeset
    98
    //   var brd = new BoardArr();
c2bf15c3b80b Add some BoardObj routines.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 8
diff changeset
    99
    //   for (i = 0; i < N; i++) {
c2bf15c3b80b Add some BoardObj routines.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 8
diff changeset
   100
    //     brd = brd.copy();
c2bf15c3b80b Add some BoardObj routines.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 8
diff changeset
   101
    //   }
c2bf15c3b80b Add some BoardObj routines.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 8
diff changeset
   102
    // })();
c2bf15c3b80b Add some BoardObj routines.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 8
diff changeset
   103
    // var tsTo = new Date().getTime();
c2bf15c3b80b Add some BoardObj routines.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 8
diff changeset
   104
    // console.log("BoardArr.prototype.copy|new: %f ms, %d u/s", tsTo-tsFrom, 2*i/(tsTo - tsFrom)*1000);
8
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   105
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   106
    perf("BoardArr.prototype.copy|new", function() {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   107
      this.brd = this.brd.copy();
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   108
    }, N, {brd: new BoardArr()});
93
c2bf15c3b80b Add some BoardObj routines.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 8
diff changeset
   109
    perf("BoardArr2d.prototype.copy|new", function() {
c2bf15c3b80b Add some BoardObj routines.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 8
diff changeset
   110
      this.brd = this.brd.copy();
c2bf15c3b80b Add some BoardObj routines.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 8
diff changeset
   111
    }, N, {brd: new BoardArr2d()});
c2bf15c3b80b Add some BoardObj routines.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 8
diff changeset
   112
    perf("BoardObj.prototype.copy|new", function() {
c2bf15c3b80b Add some BoardObj routines.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 8
diff changeset
   113
      this.brd = this.brd.copy();
c2bf15c3b80b Add some BoardObj routines.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 8
diff changeset
   114
    }, N, {brd: new BoardObj()});
c2bf15c3b80b Add some BoardObj routines.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 8
diff changeset
   115
8
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   116
    perf("BoardArr.prototype.copy|from-to", function() {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   117
      this.from.copy(this.to);
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   118
    }, N, {from: new BoardArr(), to: new BoardArr()});
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   119
    perf("BoardArr2d.prototype.copy|from-to", function() {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   120
      this.from.copy(this.to);
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   121
    }, N, {from: new BoardArr2d(), to: new BoardArr2d()});
93
c2bf15c3b80b Add some BoardObj routines.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 8
diff changeset
   122
    perf("BoardObj.prototype.copy|from-to", function() {
c2bf15c3b80b Add some BoardObj routines.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 8
diff changeset
   123
      this.from.copy(this.to);
c2bf15c3b80b Add some BoardObj routines.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 8
diff changeset
   124
    }, N, {from: new BoardObj(), to: new BoardObj()});
c2bf15c3b80b Add some BoardObj routines.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 8
diff changeset
   125
8
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   126
    perf("BoardArr2d.prototype.shiftLeft_unrolled", function() {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   127
      this.from.shiftLeft_unrolled(this.to);
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   128
      var swap = this.from; this.from = this.to, this.to = swap;
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   129
    }, N, {from: new BoardArr2d(), to: new BoardArr2d()});
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   130
    perf("BoardArr2d.prototype.shiftLeft_mostly_unrolled", function() {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   131
      this.from.shiftLeft_mostly_unrolled(this.to);
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   132
      var swap = this.from; this.from = this.to, this.to = swap;
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   133
    }, N, {from: new BoardArr2d(), to: new BoardArr2d()});
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   134
  </script>
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   135
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   136
  <script>
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   137
    /* 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
   138
    Array.prototype.forEach.call(document.querySelectorAll("button"), function(btn) {
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   139
      console.log(btn)
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   140
    });
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   141
  </script>
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   142
</body>
395195ae7daf Different performance metrics.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   143
</html>