nashorn/test/examples/apply_to_call_benchmark.js
author skovalev
Fri, 11 Dec 2015 16:35:59 +0300
changeset 34692 cfb24ebd8fb2
parent 24778 2ff5d7041566
permissions -rw-r--r--
8078423: [TESTBUG] javax/print/PrintSEUmlauts/PrintSEUmlauts.java relies on system locale Reviewed-by: martin
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
24738
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
diff changeset
     1
var Class = {
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
diff changeset
     2
  create: function() {
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
diff changeset
     3
    return function() { //vararg
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
diff changeset
     4
        this.initialize.apply(this, arguments);
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
diff changeset
     5
    }
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
diff changeset
     6
  }
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
diff changeset
     7
};
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
diff changeset
     8
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
diff changeset
     9
Color = Class.create();
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
diff changeset
    10
Color.prototype = {
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
diff changeset
    11
    red: 0, green: 0, blue: 0,
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
diff changeset
    12
    initialize: function(r,g,b) {
24778
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 24738
diff changeset
    13
    this.red = r;
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 24738
diff changeset
    14
    this.green = g;
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 24738
diff changeset
    15
    this.blue = b;
24738
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
diff changeset
    16
    }
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
diff changeset
    17
}
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
diff changeset
    18
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
diff changeset
    19
function bench(x) {
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
diff changeset
    20
    var d = new Date;
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
diff changeset
    21
    var colors = new Array(16);
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
diff changeset
    22
    for (var i=0;i<1e8;i++) {
24778
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 24738
diff changeset
    23
    colors[i&0xf] = (new Color(1,2,3));
24738
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
diff changeset
    24
    }
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
diff changeset
    25
    print(new Date - d);
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
diff changeset
    26
    return colors;
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
diff changeset
    27
}
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
diff changeset
    28
bench(17);
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
diff changeset
    29
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
diff changeset
    30
print("Swapping out call");
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
diff changeset
    31
Function.prototype.call = function() {
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
diff changeset
    32
    throw "This should not happen, apply should be called instead";
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
diff changeset
    33
};
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
diff changeset
    34
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
diff changeset
    35
bench(17);
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
diff changeset
    36
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
diff changeset
    37
print("All done!");