hannesw@1074: /* hannesw@1074: * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. hannesw@1074: * hannesw@1074: * Redistribution and use in source and binary forms, with or without hannesw@1074: * modification, are permitted provided that the following conditions hannesw@1074: * are met: hannesw@1074: * hannesw@1074: * - Redistributions of source code must retain the above copyright hannesw@1074: * notice, this list of conditions and the following disclaimer. hannesw@1074: * hannesw@1074: * - Redistributions in binary form must reproduce the above copyright hannesw@1074: * notice, this list of conditions and the following disclaimer in the hannesw@1074: * documentation and/or other materials provided with the distribution. hannesw@1074: * hannesw@1074: * - Neither the name of Oracle nor the names of its hannesw@1074: * contributors may be used to endorse or promote products derived hannesw@1074: * from this software without specific prior written permission. hannesw@1074: * hannesw@1074: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS hannesw@1074: * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, hannesw@1074: * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR hannesw@1074: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR hannesw@1074: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, hannesw@1074: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, hannesw@1074: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR hannesw@1074: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF hannesw@1074: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING hannesw@1074: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS hannesw@1074: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. hannesw@1074: */ hannesw@1074: hannesw@1074: /* hannesw@1074: * A micro-benchmark for getters and setters with primitive values, hannesw@1074: * alternating between ints and doubles. Introduction of primitive hannesw@1074: * and optimistic user accessors in JDK-8062401 make this faster by hannesw@1074: * 10x or more by allowing inlining and other optimizations to take place. hannesw@1074: */ hannesw@1074: hannesw@1074: var x = { hannesw@1074: get m() { hannesw@1074: return this._m; hannesw@1074: }, hannesw@1074: set m(v) { hannesw@1074: this._m = v; hannesw@1074: }, hannesw@1074: get n() { hannesw@1074: return this._n; hannesw@1074: }, hannesw@1074: set n(v) { hannesw@1074: this._n = v; hannesw@1074: } hannesw@1074: }; hannesw@1074: hannesw@1074: hannesw@1074: function bench(v1, v2, result) { hannesw@1074: var start = Date.now(); hannesw@1074: x.n = v1; hannesw@1074: for (var i = 0; i < 1e8; i++) { hannesw@1074: x.m = v2; hannesw@1074: if (x.m + x.n !== result) { hannesw@1074: throw "wrong result"; hannesw@1074: } hannesw@1074: } hannesw@1074: print("done in", Date.now() - start, "millis"); hannesw@1074: } hannesw@1074: hannesw@1074: for (var i = 0; i < 10; i++) { hannesw@1074: bench(i, 4, 4 + i); hannesw@1074: } hannesw@1074: hannesw@1074: for (var i = 0; i < 10; i++) { hannesw@1074: bench(i, 4.5, 4.5 + i); hannesw@1074: } hannesw@1074: hannesw@1074: for (var i = 0; i < 10; i++) { hannesw@1074: bench(i, 5, 5 + i); hannesw@1074: } hannesw@1074: hannesw@1074: for (var i = 0; i < 10; i++) { hannesw@1074: bench(i, 5.5, 5.5 + i); hannesw@1074: }