Mon, 11 Jan 2016 13:45:31 -0800
Added tag jdk8u75-b03 for changeset 541de42b5709
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 charCodeAt specialized method performance |
lagergren@1028 | 26 | */ |
lagergren@1028 | 27 | |
lagergren@1028 | 28 | var str = "sghjkdsfkjghsdfjkfkjdfkjdfjkdfjkfdjkfdkfldjfhdfpkjdhafgksdjfgldfgjldfkjgdlfjgldkfjgkldfj"; |
lagergren@1028 | 29 | var RESULT1 = 9187; |
lagergren@1028 | 30 | var RESULT2 = 1496; |
lagergren@1028 | 31 | |
lagergren@1028 | 32 | function f() { |
lagergren@1028 | 33 | var len = str.length; |
lagergren@1028 | 34 | var c = 0; |
lagergren@1028 | 35 | for (var i = 0; i < len; i++) { |
lagergren@1028 | 36 | c += str.charCodeAt(i); |
lagergren@1028 | 37 | } |
lagergren@1028 | 38 | return c; |
lagergren@1028 | 39 | } |
lagergren@1028 | 40 | |
lagergren@1028 | 41 | function bench(res) { |
lagergren@1028 | 42 | var d = new Date; |
lagergren@1028 | 43 | var sum = 0; |
lagergren@1028 | 44 | for (var i = 0; i < 1e6; i++) { |
lagergren@1028 | 45 | sum |= f(); |
lagergren@1028 | 46 | } |
lagergren@1028 | 47 | if (sum == res) { |
lagergren@1028 | 48 | print("Verified OK"); |
lagergren@1028 | 49 | } else { |
lagergren@1028 | 50 | print("Verification failed " + sum + " should be " + res); |
lagergren@1028 | 51 | } |
lagergren@1028 | 52 | print((new Date - d) + " ms"); |
lagergren@1028 | 53 | } |
lagergren@1028 | 54 | |
lagergren@1028 | 55 | bench(RESULT1); |
lagergren@1028 | 56 | |
lagergren@1028 | 57 | print("Replacing charCodeAt... "); |
lagergren@1028 | 58 | |
lagergren@1028 | 59 | String.prototype.charCodeAt = function() { return 17; } |
lagergren@1028 | 60 | |
lagergren@1028 | 61 | bench(RESULT2); |
lagergren@1028 | 62 | |
lagergren@1028 | 63 | print("Done"); |