attila@963: /* attila@963: * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved. attila@963: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. attila@963: * attila@963: * This code is free software; you can redistribute it and/or modify it attila@963: * under the terms of the GNU General Public License version 2 only, as attila@963: * published by the Free Software Foundation. attila@963: * attila@963: * This code is distributed in the hope that it will be useful, but WITHOUT attila@963: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or attila@963: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License attila@963: * version 2 for more details (a copy is included in the LICENSE file that attila@963: * accompanied this code). attila@963: * attila@963: * You should have received a copy of the GNU General Public License version attila@963: * 2 along with this work; if not, write to the Free Software Foundation, attila@963: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. attila@963: * attila@963: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA attila@963: * or visit www.oracle.com if you need additional information or have any attila@963: * questions. attila@963: */ attila@963: attila@963: /** attila@963: * sanity check that apply to call specialization is faster than apply. attila@963: * attila@963: * @test attila@963: * @run attila@963: */ attila@963: attila@963: var Class = { attila@963: create: function() { attila@963: return function() { //vararg attila@963: this.initialize.apply(this, arguments); attila@963: } attila@963: } attila@963: }; attila@963: attila@963: Color = Class.create(); attila@963: Color.prototype = { attila@963: red: 0, green: 0, blue: 0, attila@963: initialize: function(r,g,b) { attila@963: this.red = r; attila@963: this.green = g; attila@963: this.blue = b; attila@963: } attila@963: }; attila@963: attila@963: var time1 = 0; attila@963: var time2 = 0; attila@963: attila@963: function set_time1(t) { attila@963: time1 = t; attila@963: } attila@963: attila@963: function set_time2(t) { attila@963: time2 = t; attila@963: } attila@963: attila@963: function bench(x, set_time) { attila@963: var d = new Date; attila@963: var colors = new Array(16); attila@963: for (var i=0;i<1e8;i++) { attila@963: colors[i & 0xf] = new Color(1,2,3); attila@963: } attila@963: var t = new Date - d; attila@963: set_time(t); attila@963: return colors; attila@963: } attila@963: attila@963: //warmup attila@963: print("Running warmup"); attila@963: bench(17, set_time1); attila@963: attila@963: print("Running sharp run"); attila@963: bench(17, set_time1); attila@963: attila@963: print("Swapping out call"); attila@963: Function.prototype.call = function() { attila@963: throw "This should not happen, apply should be called instead"; attila@963: }; attila@963: attila@963: print("Rerunning invalidated"); attila@963: bench(17, set_time2); attila@963: attila@963: print("All done!"); attila@963: attila@963: if (time1 > time2) { attila@963: print("ERROR: time1 > time2 (" + time1 + " > " + time2 + ")"); attila@963: } else { attila@963: print("Times OK"); attila@963: } attila@963: