test/examples/push-pop-benchmark.js

Mon, 26 Sep 2016 14:38:22 -0700

author
asaha
date
Mon, 26 Sep 2016 14:38:22 -0700
changeset 1995
42c34892b742
parent 1028
d79265f2fa92
permissions
-rw-r--r--

Added tag jdk8u121-b02 for changeset 33bf988e6f1a

lagergren@1028 1 /*
lagergren@1028 2 * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
lagergren@1028 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
lagergren@1028 4 *
lagergren@1028 5 * This code is free software; you can redistribute it and/or modify it
lagergren@1028 6 * under the terms of the GNU General Public License version 2 only, as
lagergren@1028 7 * published by the Free Software Foundation.
lagergren@1028 8 *
lagergren@1028 9 * This code is distributed in the hope that it will be useful, but WITHOUT
lagergren@1028 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
lagergren@1028 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
lagergren@1028 12 * version 2 for more details (a copy is included in the LICENSE file that
lagergren@1028 13 * accompanied this code).
lagergren@1028 14 *
lagergren@1028 15 * You should have received a copy of the GNU General Public License version
lagergren@1028 16 * 2 along with this work; if not, write to the Free Software Foundation,
lagergren@1028 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
lagergren@1028 18 *
lagergren@1028 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
lagergren@1028 20 * or visit www.oracle.com if you need additional information or have any
lagergren@1028 21 * questions.
lagergren@1028 22 */
lagergren@1028 23
lagergren@1028 24 /**
lagergren@1028 25 * Simple benchmark to measure push/pop specialized method performance
lagergren@1028 26 */
lagergren@1028 27
lagergren@1028 28 var a = [];
lagergren@1028 29
lagergren@1028 30 var RESULT = 15;
lagergren@1028 31
lagergren@1028 32 function bench() {
lagergren@1028 33 var sum = 0;
lagergren@1028 34 for (var i=0;i<10;i++) {
lagergren@1028 35 a.push(i);
lagergren@1028 36 }
lagergren@1028 37 for (var i=0;i<10;i++) {
lagergren@1028 38 sum |= a.pop();
lagergren@1028 39 }
lagergren@1028 40 return sum;
lagergren@1028 41 }
lagergren@1028 42
lagergren@1028 43 function runbench() {
lagergren@1028 44 var sum = 0;
lagergren@1028 45 for (var iters = 0; iters<1e8; iters++) {
lagergren@1028 46 sum |= bench();
lagergren@1028 47 }
lagergren@1028 48 return sum;
lagergren@1028 49 }
lagergren@1028 50
lagergren@1028 51 var d = new Date;
lagergren@1028 52 var res = runbench();
lagergren@1028 53 print((new Date - d) + " ms");
lagergren@1028 54 print();
lagergren@1028 55 if (res != RESULT) {
lagergren@1028 56 print("ERROR: Wrong result - should be " + RESULT);
lagergren@1028 57 } else {
lagergren@1028 58 print("Verified OK - result is correct");
lagergren@1028 59 }

mercurial