Mon, 11 Jan 2016 13:45:31 -0800
Added tag jdk8u75-b03 for changeset 541de42b5709
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. |
attila@962 | 3 | * |
aoqi@0 | 4 | * Redistribution and use in source and binary forms, with or without |
aoqi@0 | 5 | * modification, are permitted provided that the following conditions |
aoqi@0 | 6 | * are met: |
attila@962 | 7 | * |
aoqi@0 | 8 | * - Redistributions of source code must retain the above copyright |
aoqi@0 | 9 | * notice, this list of conditions and the following disclaimer. |
attila@962 | 10 | * |
aoqi@0 | 11 | * - Redistributions in binary form must reproduce the above copyright |
aoqi@0 | 12 | * notice, this list of conditions and the following disclaimer in the |
aoqi@0 | 13 | * documentation and/or other materials provided with the distribution. |
attila@962 | 14 | * |
aoqi@0 | 15 | * - Neither the name of Oracle nor the names of its |
aoqi@0 | 16 | * contributors may be used to endorse or promote products derived |
aoqi@0 | 17 | * from this software without specific prior written permission. |
attila@962 | 18 | * |
aoqi@0 | 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS |
aoqi@0 | 20 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
aoqi@0 | 21 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
aoqi@0 | 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
aoqi@0 | 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
aoqi@0 | 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
aoqi@0 | 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
aoqi@0 | 26 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
aoqi@0 | 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
aoqi@0 | 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
aoqi@0 | 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
aoqi@0 | 30 | */ |
aoqi@0 | 31 | |
aoqi@0 | 32 | |
aoqi@0 | 33 | var str = "The quick gray nashorn jumps over the lazy zebra."; |
aoqi@0 | 34 | |
aoqi@0 | 35 | function bench(name, func) { |
aoqi@0 | 36 | var start = Date.now(); |
aoqi@0 | 37 | for (var iter = 0; iter < 5000000; iter++) { |
aoqi@0 | 38 | func(); |
aoqi@0 | 39 | } |
aoqi@0 | 40 | print((Date.now() - start) + "\t" + name); |
aoqi@0 | 41 | } |
aoqi@0 | 42 | |
aoqi@0 | 43 | bench("[]", function() { |
aoqi@0 | 44 | str[0]; |
aoqi@0 | 45 | str[1]; |
aoqi@0 | 46 | str[2]; |
aoqi@0 | 47 | }); |
aoqi@0 | 48 | |
attila@963 | 49 | bench("fromCharCode 1", function() { |
aoqi@0 | 50 | String.fromCharCode(97); |
aoqi@0 | 51 | String.fromCharCode(98); |
aoqi@0 | 52 | String.fromCharCode(99); |
aoqi@0 | 53 | }); |
aoqi@0 | 54 | |
attila@963 | 55 | bench("fromCharCode 2", function() { |
attila@963 | 56 | String.fromCharCode(97, 98); |
attila@963 | 57 | String.fromCharCode(97, 98, 99); |
attila@963 | 58 | String.fromCharCode(97, 98, 99, 100); |
attila@963 | 59 | }); |
attila@963 | 60 | |
aoqi@0 | 61 | bench("charAt 1", function() { |
aoqi@0 | 62 | str.charAt(0); |
aoqi@0 | 63 | str.charAt(1); |
aoqi@0 | 64 | str.charAt(2); |
aoqi@0 | 65 | }); |
aoqi@0 | 66 | |
aoqi@0 | 67 | bench("charAt 2", function() { |
aoqi@0 | 68 | str.charAt(100); |
aoqi@0 | 69 | str.charAt(-1); |
aoqi@0 | 70 | }); |
aoqi@0 | 71 | |
aoqi@0 | 72 | bench("charCodeAt 1", function() { |
aoqi@0 | 73 | str.charCodeAt(0); |
aoqi@0 | 74 | str.charCodeAt(1); |
aoqi@0 | 75 | str.charCodeAt(2); |
aoqi@0 | 76 | }); |
aoqi@0 | 77 | |
aoqi@0 | 78 | bench("charCodeAt 2", function() { |
aoqi@0 | 79 | str.charCodeAt(100); |
aoqi@0 | 80 | str.charCodeAt(-1); |
aoqi@0 | 81 | }); |
aoqi@0 | 82 | |
aoqi@0 | 83 | bench("indexOf 1", function() { |
aoqi@0 | 84 | str.indexOf("T"); |
aoqi@0 | 85 | str.indexOf("h"); |
aoqi@0 | 86 | str.indexOf("e"); |
aoqi@0 | 87 | }); |
aoqi@0 | 88 | |
aoqi@0 | 89 | bench("indexOf 2", function() { |
aoqi@0 | 90 | str.indexOf("T", 0); |
aoqi@0 | 91 | str.indexOf("h", 1); |
aoqi@0 | 92 | str.indexOf("e", 2); |
aoqi@0 | 93 | }); |
aoqi@0 | 94 | |
aoqi@0 | 95 | bench("lastIndexOf", function() { |
aoqi@0 | 96 | str.indexOf("a"); |
aoqi@0 | 97 | str.indexOf("r"); |
aoqi@0 | 98 | str.indexOf("b"); |
aoqi@0 | 99 | }); |
aoqi@0 | 100 | |
aoqi@0 | 101 | bench("slice", function() { |
aoqi@0 | 102 | str.slice(5); |
aoqi@0 | 103 | str.slice(5); |
aoqi@0 | 104 | str.slice(5); |
aoqi@0 | 105 | }); |
aoqi@0 | 106 | |
aoqi@0 | 107 | bench("split 1", function() { |
aoqi@0 | 108 | str.split(); |
aoqi@0 | 109 | }); |
aoqi@0 | 110 | |
aoqi@0 | 111 | bench("split 2", function() { |
aoqi@0 | 112 | str.split("foo"); |
aoqi@0 | 113 | }); |
aoqi@0 | 114 | |
aoqi@0 | 115 | bench("split 3", function() { |
aoqi@0 | 116 | str.split(/foo/); |
aoqi@0 | 117 | }); |
aoqi@0 | 118 | |
aoqi@0 | 119 | bench("substring 1", function() { |
aoqi@0 | 120 | str.substring(0); |
aoqi@0 | 121 | str.substring(0); |
aoqi@0 | 122 | str.substring(0); |
aoqi@0 | 123 | }); |
aoqi@0 | 124 | |
aoqi@0 | 125 | bench("substring 2", function() { |
aoqi@0 | 126 | str.substring(0, 5); |
aoqi@0 | 127 | str.substring(0, 5); |
aoqi@0 | 128 | str.substring(0, 5); |
aoqi@0 | 129 | }); |
aoqi@0 | 130 | |
aoqi@0 | 131 | bench("substr", function() { |
aoqi@0 | 132 | str.substr(0); |
aoqi@0 | 133 | str.substr(0); |
aoqi@0 | 134 | str.substr(0); |
aoqi@0 | 135 | }); |
aoqi@0 | 136 | |
aoqi@0 | 137 | bench("slice", function() { |
aoqi@0 | 138 | str.slice(0); |
aoqi@0 | 139 | str.slice(0); |
aoqi@0 | 140 | str.slice(0); |
aoqi@0 | 141 | }); |
aoqi@0 | 142 | |
aoqi@0 | 143 | bench("concat", function() { |
aoqi@0 | 144 | str.concat(str); |
aoqi@0 | 145 | str.concat(str); |
aoqi@0 | 146 | str.concat(str); |
aoqi@0 | 147 | }); |
aoqi@0 | 148 | |
aoqi@0 | 149 | bench("trim", function() { |
aoqi@0 | 150 | str.trim(); |
aoqi@0 | 151 | str.trim(); |
aoqi@0 | 152 | str.trim(); |
aoqi@0 | 153 | }); |
aoqi@0 | 154 | |
aoqi@0 | 155 | bench("toUpperCase", function() { |
aoqi@0 | 156 | str.toUpperCase(); |
aoqi@0 | 157 | }); |
aoqi@0 | 158 | |
aoqi@0 | 159 | bench("toLowerCase", function() { |
aoqi@0 | 160 | str.toLowerCase(); |
aoqi@0 | 161 | }); |
aoqi@0 | 162 | |
aoqi@0 | 163 | bench("valueOf", function() { |
aoqi@0 | 164 | str.valueOf(); |
aoqi@0 | 165 | str.valueOf(); |
aoqi@0 | 166 | str.valueOf(); |
aoqi@0 | 167 | }); |
aoqi@0 | 168 | |
aoqi@0 | 169 | bench("toString", function() { |
aoqi@0 | 170 | str.toString(); |
aoqi@0 | 171 | str.toString(); |
aoqi@0 | 172 | str.toString(); |
aoqi@0 | 173 | }); |
aoqi@0 | 174 | |
aoqi@0 | 175 | bench("String", function() { |
aoqi@0 | 176 | String(str); |
aoqi@0 | 177 | String(str); |
aoqi@0 | 178 | String(str); |
aoqi@0 | 179 | }); |
aoqi@0 | 180 | |
aoqi@0 | 181 | bench("new String", function() { |
aoqi@0 | 182 | new String(str); |
aoqi@0 | 183 | new String(str); |
aoqi@0 | 184 | new String(str); |
aoqi@0 | 185 | }); |