Path: blob/aarch64-shenandoah-jdk8u272-b10/nashorn/test/script/currently-failing/apply_to_call_bench.js
32281 views
/*1* Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/**24* sanity check that apply to call specialization is faster than apply.25*26* @test27* @run28*/2930var Class = {31create: function() {32return function() { //vararg33this.initialize.apply(this, arguments);34}35}36};3738Color = Class.create();39Color.prototype = {40red: 0, green: 0, blue: 0,41initialize: function(r,g,b) {42this.red = r;43this.green = g;44this.blue = b;45}46};4748var time1 = 0;49var time2 = 0;5051function set_time1(t) {52time1 = t;53}5455function set_time2(t) {56time2 = t;57}5859function bench(x, set_time) {60var d = new Date;61var colors = new Array(16);62for (var i=0;i<1e8;i++) {63colors[i & 0xf] = new Color(1,2,3);64}65var t = new Date - d;66set_time(t);67return colors;68}6970//warmup71print("Running warmup");72bench(17, set_time1);7374print("Running sharp run");75bench(17, set_time1);7677print("Swapping out call");78Function.prototype.call = function() {79throw "This should not happen, apply should be called instead";80};8182print("Rerunning invalidated");83bench(17, set_time2);8485print("All done!");8687if (time1 > time2) {88print("ERROR: time1 > time2 (" + time1 + " > " + time2 + ")");89} else {90print("Times OK");91}92939495