test/examples/json-parser-micro.js

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

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

Added tag jdk8u121-b02 for changeset 33bf988e6f1a

hannesw@1228 1 /*
hannesw@1228 2 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
hannesw@1228 3 *
hannesw@1228 4 * Redistribution and use in source and binary forms, with or without
hannesw@1228 5 * modification, are permitted provided that the following conditions
hannesw@1228 6 * are met:
hannesw@1228 7 *
hannesw@1228 8 * - Redistributions of source code must retain the above copyright
hannesw@1228 9 * notice, this list of conditions and the following disclaimer.
hannesw@1228 10 *
hannesw@1228 11 * - Redistributions in binary form must reproduce the above copyright
hannesw@1228 12 * notice, this list of conditions and the following disclaimer in the
hannesw@1228 13 * documentation and/or other materials provided with the distribution.
hannesw@1228 14 *
hannesw@1228 15 * - Neither the name of Oracle nor the names of its
hannesw@1228 16 * contributors may be used to endorse or promote products derived
hannesw@1228 17 * from this software without specific prior written permission.
hannesw@1228 18 *
hannesw@1228 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
hannesw@1228 20 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
hannesw@1228 21 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
hannesw@1228 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
hannesw@1228 23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
hannesw@1228 24 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
hannesw@1228 25 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
hannesw@1228 26 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
hannesw@1228 27 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
hannesw@1228 28 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
hannesw@1228 29 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
hannesw@1228 30 */
hannesw@1228 31
hannesw@1228 32 function bench() {
hannesw@1228 33 var start = Date.now();
hannesw@1228 34 for (var i = 0; i < 2000; i++) {
hannesw@1228 35 JSON.parse(String(json));
hannesw@1228 36 }
hannesw@1228 37 print("1000 iterations in", Date.now() - start, "millis");
hannesw@1228 38 }
hannesw@1228 39
hannesw@1228 40 var json = '[\
hannesw@1228 41 {\
hannesw@1228 42 "_id": "54ca34171d3ade49782294c8",\
hannesw@1228 43 "index": 0,\
hannesw@1228 44 "guid": "ed0e74d5-ac63-47b6-8938-1750abab5770",\
hannesw@1228 45 "isActive": false,\
hannesw@1228 46 "balance": "$1,996.19",\
hannesw@1228 47 "picture": "http://placehold.it/32x32",\
hannesw@1228 48 "age": 39,\
hannesw@1228 49 "eyeColor": "green",\
hannesw@1228 50 "name": "Rose Graham",\
hannesw@1228 51 "gender": "male",\
hannesw@1228 52 "company": "PRIMORDIA",\
hannesw@1228 53 "email": "rosegraham@primordia.com",\
hannesw@1228 54 "phone": "+1 (985) 600-3551",\
hannesw@1228 55 "address": "364 Melba Court, Succasunna, Texas, 8393",\
hannesw@1228 56 "about": "Sunt commodo cillum occaecat velit eu eiusmod ex eiusmod sunt deserunt nulla proident incididunt. Incididunt ullamco Lorem elit do culpa esse do ex dolor aliquip labore. Ullamco velit laboris incididunt dolor. Nostrud dolor sint pariatur fugiat ullamco exercitation. Eu laboris do cupidatat eiusmod incididunt mollit occaecat voluptate.",\
hannesw@1228 57 "registered": "2014-03-13T12:05:14 -01:00",\
hannesw@1228 58 "latitude": 18.55665,\
hannesw@1228 59 "longitude": 81.641001,\
hannesw@1228 60 "tags": [\
hannesw@1228 61 "sint",\
hannesw@1228 62 "Lorem",\
hannesw@1228 63 "veniam",\
hannesw@1228 64 "quis",\
hannesw@1228 65 "proident",\
hannesw@1228 66 "consectetur",\
hannesw@1228 67 "consequat"\
hannesw@1228 68 ],\
hannesw@1228 69 "friends": [\
hannesw@1228 70 {\
hannesw@1228 71 "id": 0,\
hannesw@1228 72 "name": "Evangelina Morgan"\
hannesw@1228 73 },\
hannesw@1228 74 {\
hannesw@1228 75 "id": 1,\
hannesw@1228 76 "name": "Saunders Snyder"\
hannesw@1228 77 },\
hannesw@1228 78 {\
hannesw@1228 79 "id": 2,\
hannesw@1228 80 "name": "Walker Wood"\
hannesw@1228 81 }\
hannesw@1228 82 ],\
hannesw@1228 83 "greeting": "Hello, Rose Graham! You have 1 unread messages.",\
hannesw@1228 84 "favoriteFruit": "strawberry"\
hannesw@1228 85 },\
hannesw@1228 86 {\
hannesw@1228 87 "_id": "54ca34176790c4c60fcae085",\
hannesw@1228 88 "index": 1,\
hannesw@1228 89 "guid": "9dc42e4c-b58f-4d92-a2ee-968d2b627d92",\
hannesw@1228 90 "isActive": true,\
hannesw@1228 91 "balance": "$3,832.97",\
hannesw@1228 92 "picture": "http://placehold.it/32x32",\
hannesw@1228 93 "age": 40,\
hannesw@1228 94 "eyeColor": "brown",\
hannesw@1228 95 "name": "Delaney Cherry",\
hannesw@1228 96 "gender": "male",\
hannesw@1228 97 "company": "INJOY",\
hannesw@1228 98 "email": "delaneycherry@injoy.com",\
hannesw@1228 99 "phone": "+1 (807) 463-2295",\
hannesw@1228 100 "address": "470 Hale Avenue, Mulberry, District Of Columbia, 5455",\
hannesw@1228 101 "about": "Deserunt sit cupidatat elit Lorem excepteur ex. Magna officia minim cupidatat nulla enim deserunt. Amet ex in tempor commodo consequat non ad qui elit cupidatat esse labore sint.",\
hannesw@1228 102 "registered": "2014-03-27T23:06:33 -01:00",\
hannesw@1228 103 "latitude": -4.984238,\
hannesw@1228 104 "longitude": 116.039285,\
hannesw@1228 105 "tags": [\
hannesw@1228 106 "minim",\
hannesw@1228 107 "velit",\
hannesw@1228 108 "aute",\
hannesw@1228 109 "minim",\
hannesw@1228 110 "id",\
hannesw@1228 111 "enim",\
hannesw@1228 112 "enim"\
hannesw@1228 113 ],\
hannesw@1228 114 "friends": [\
hannesw@1228 115 {\
hannesw@1228 116 "id": 0,\
hannesw@1228 117 "name": "Barrera Flowers"\
hannesw@1228 118 },\
hannesw@1228 119 {\
hannesw@1228 120 "id": 1,\
hannesw@1228 121 "name": "Leann Larson"\
hannesw@1228 122 },\
hannesw@1228 123 {\
hannesw@1228 124 "id": 2,\
hannesw@1228 125 "name": "Latoya Petty"\
hannesw@1228 126 }\
hannesw@1228 127 ],\
hannesw@1228 128 "greeting": "Hello, Delaney Cherry! You have 2 unread messages.",\
hannesw@1228 129 "favoriteFruit": "strawberry"\
hannesw@1228 130 },\
hannesw@1228 131 {\
hannesw@1228 132 "_id": "54ca3417920666f00c54bfc4",\
hannesw@1228 133 "index": 2,\
hannesw@1228 134 "guid": "f91e08f8-1598-49bc-a08b-bb48f0cc1751",\
hannesw@1228 135 "isActive": true,\
hannesw@1228 136 "balance": "$2,932.84",\
hannesw@1228 137 "picture": "http://placehold.it/32x32",\
hannesw@1228 138 "age": 28,\
hannesw@1228 139 "eyeColor": "brown",\
hannesw@1228 140 "name": "Mosley Hammond",\
hannesw@1228 141 "gender": "male",\
hannesw@1228 142 "company": "AQUACINE",\
hannesw@1228 143 "email": "mosleyhammond@aquacine.com",\
hannesw@1228 144 "phone": "+1 (836) 598-2591",\
hannesw@1228 145 "address": "879 Columbia Place, Seymour, Montana, 4897",\
hannesw@1228 146 "about": "Sunt laborum incididunt et elit in deserunt deserunt irure enim ea qui non. Minim nisi sint aute veniam reprehenderit veniam reprehenderit. Elit enim eu voluptate eu cupidatat nulla ea incididunt exercitation voluptate ut aliquip excepteur ipsum. Consequat anim fugiat irure Lorem anim consectetur est.",\
hannesw@1228 147 "registered": "2014-07-27T05:05:58 -02:00",\
hannesw@1228 148 "latitude": -43.608015,\
hannesw@1228 149 "longitude": -38.33894,\
hannesw@1228 150 "tags": [\
hannesw@1228 151 "proident",\
hannesw@1228 152 "incididunt",\
hannesw@1228 153 "eiusmod",\
hannesw@1228 154 "anim",\
hannesw@1228 155 "consectetur",\
hannesw@1228 156 "qui",\
hannesw@1228 157 "excepteur"\
hannesw@1228 158 ],\
hannesw@1228 159 "friends": [\
hannesw@1228 160 {\
hannesw@1228 161 "id": 0,\
hannesw@1228 162 "name": "Hanson Davidson"\
hannesw@1228 163 },\
hannesw@1228 164 {\
hannesw@1228 165 "id": 1,\
hannesw@1228 166 "name": "Autumn Kaufman"\
hannesw@1228 167 },\
hannesw@1228 168 {\
hannesw@1228 169 "id": 2,\
hannesw@1228 170 "name": "Tammy Foley"\
hannesw@1228 171 }\
hannesw@1228 172 ],\
hannesw@1228 173 "greeting": "Hello, Mosley Hammond! You have 4 unread messages.",\
hannesw@1228 174 "favoriteFruit": "apple"\
hannesw@1228 175 },\
hannesw@1228 176 {\
hannesw@1228 177 "_id": "54ca341753b67572a2b04935",\
hannesw@1228 178 "index": 3,\
hannesw@1228 179 "guid": "3377416b-43a2-4f9e-ada3-2479e13b44b8",\
hannesw@1228 180 "isActive": false,\
hannesw@1228 181 "balance": "$3,821.54",\
hannesw@1228 182 "picture": "http://placehold.it/32x32",\
hannesw@1228 183 "age": 31,\
hannesw@1228 184 "eyeColor": "green",\
hannesw@1228 185 "name": "Mueller Barrett",\
hannesw@1228 186 "gender": "male",\
hannesw@1228 187 "company": "GROK",\
hannesw@1228 188 "email": "muellerbarrett@grok.com",\
hannesw@1228 189 "phone": "+1 (890) 535-2834",\
hannesw@1228 190 "address": "571 Norwood Avenue, Westwood, Arkansas, 2164",\
hannesw@1228 191 "about": "Occaecat est sunt commodo ut ex excepteur elit nulla velit minim commodo commodo esse. Lorem quis eu minim consectetur. Cupidatat cupidatat consequat sit eu ex non quis nulla veniam sint enim excepteur. Consequat minim duis do do minim fugiat minim elit laborum ut velit. Occaecat laboris veniam sint reprehenderit.",\
hannesw@1228 192 "registered": "2014-07-18T17:15:35 -02:00",\
hannesw@1228 193 "latitude": 10.746577,\
hannesw@1228 194 "longitude": -160.266041,\
hannesw@1228 195 "tags": [\
hannesw@1228 196 "reprehenderit",\
hannesw@1228 197 "veniam",\
hannesw@1228 198 "sint",\
hannesw@1228 199 "commodo",\
hannesw@1228 200 "exercitation",\
hannesw@1228 201 "cillum",\
hannesw@1228 202 "sunt"\
hannesw@1228 203 ],\
hannesw@1228 204 "friends": [\
hannesw@1228 205 {\
hannesw@1228 206 "id": 0,\
hannesw@1228 207 "name": "Summers Finch"\
hannesw@1228 208 },\
hannesw@1228 209 {\
hannesw@1228 210 "id": 1,\
hannesw@1228 211 "name": "Tracie Mcdaniel"\
hannesw@1228 212 },\
hannesw@1228 213 {\
hannesw@1228 214 "id": 2,\
hannesw@1228 215 "name": "Ayers Patrick"\
hannesw@1228 216 }\
hannesw@1228 217 ],\
hannesw@1228 218 "greeting": "Hello, Mueller Barrett! You have 7 unread messages.",\
hannesw@1228 219 "favoriteFruit": "apple"\
hannesw@1228 220 },\
hannesw@1228 221 {\
hannesw@1228 222 "_id": "54ca34172775ab9615db0d1d",\
hannesw@1228 223 "index": 4,\
hannesw@1228 224 "guid": "a3102a3e-3f08-4df3-b5b5-62eff985d5ca",\
hannesw@1228 225 "isActive": true,\
hannesw@1228 226 "balance": "$3,962.27",\
hannesw@1228 227 "picture": "http://placehold.it/32x32",\
hannesw@1228 228 "age": 34,\
hannesw@1228 229 "eyeColor": "green",\
hannesw@1228 230 "name": "Patrick Foster",\
hannesw@1228 231 "gender": "male",\
hannesw@1228 232 "company": "QUAREX",\
hannesw@1228 233 "email": "patrickfoster@quarex.com",\
hannesw@1228 234 "phone": "+1 (805) 577-2362",\
hannesw@1228 235 "address": "640 Richards Street, Roberts, American Samoa, 5530",\
hannesw@1228 236 "about": "Aute occaecat occaecat ad eiusmod esse aliqua ullamco minim. Exercitation aute ut ex nostrud deserunt laboris officia amet enim do. Cillum officia laborum occaecat eiusmod reprehenderit ex et aliqua minim elit ex aliqua mollit. Occaecat dolor in fugiat laboris aliquip nisi ad voluptate duis eiusmod ad do.",\
hannesw@1228 237 "registered": "2014-07-22T16:45:35 -02:00",\
hannesw@1228 238 "latitude": 6.609025,\
hannesw@1228 239 "longitude": -5.357026,\
hannesw@1228 240 "tags": [\
hannesw@1228 241 "ea",\
hannesw@1228 242 "ut",\
hannesw@1228 243 "excepteur",\
hannesw@1228 244 "enim",\
hannesw@1228 245 "ad",\
hannesw@1228 246 "non",\
hannesw@1228 247 "sit"\
hannesw@1228 248 ],\
hannesw@1228 249 "friends": [\
hannesw@1228 250 {\
hannesw@1228 251 "id": 0,\
hannesw@1228 252 "name": "Duncan Lewis"\
hannesw@1228 253 },\
hannesw@1228 254 {\
hannesw@1228 255 "id": 1,\
hannesw@1228 256 "name": "Alyce Benton"\
hannesw@1228 257 },\
hannesw@1228 258 {\
hannesw@1228 259 "id": 2,\
hannesw@1228 260 "name": "Angelique Larsen"\
hannesw@1228 261 }\
hannesw@1228 262 ],\
hannesw@1228 263 "greeting": "Hello, Patrick Foster! You have 1 unread messages.",\
hannesw@1228 264 "favoriteFruit": "strawberry"\
hannesw@1228 265 },\
hannesw@1228 266 {\
hannesw@1228 267 "_id": "54ca3417a190f26fef815f6d",\
hannesw@1228 268 "index": 5,\
hannesw@1228 269 "guid": "c09663dd-bb0e-45a4-960c-232c0e8a9486",\
hannesw@1228 270 "isActive": false,\
hannesw@1228 271 "balance": "$1,871.12",\
hannesw@1228 272 "picture": "http://placehold.it/32x32",\
hannesw@1228 273 "age": 20,\
hannesw@1228 274 "eyeColor": "blue",\
hannesw@1228 275 "name": "Foreman Chaney",\
hannesw@1228 276 "gender": "male",\
hannesw@1228 277 "company": "DEMINIMUM",\
hannesw@1228 278 "email": "foremanchaney@deminimum.com",\
hannesw@1228 279 "phone": "+1 (966) 523-2182",\
hannesw@1228 280 "address": "960 Granite Street, Sunnyside, Tennessee, 1097",\
hannesw@1228 281 "about": "Adipisicing nisi qui id sit incididunt aute exercitation veniam consequat ipsum sit irure. Aute officia commodo Lorem consequat. Labore exercitation consequat voluptate deserunt consequat do est fugiat nisi eu dolor minim id ea.",\
hannesw@1228 282 "registered": "2015-01-21T00:18:00 -01:00",\
hannesw@1228 283 "latitude": -69.841726,\
hannesw@1228 284 "longitude": 121.809383,\
hannesw@1228 285 "tags": [\
hannesw@1228 286 "laboris",\
hannesw@1228 287 "sunt",\
hannesw@1228 288 "exercitation",\
hannesw@1228 289 "enim",\
hannesw@1228 290 "anim",\
hannesw@1228 291 "excepteur",\
hannesw@1228 292 "tempor"\
hannesw@1228 293 ],\
hannesw@1228 294 "friends": [\
hannesw@1228 295 {\
hannesw@1228 296 "id": 0,\
hannesw@1228 297 "name": "Espinoza Johnston"\
hannesw@1228 298 },\
hannesw@1228 299 {\
hannesw@1228 300 "id": 1,\
hannesw@1228 301 "name": "Doreen Holder"\
hannesw@1228 302 },\
hannesw@1228 303 {\
hannesw@1228 304 "id": 2,\
hannesw@1228 305 "name": "William Ellison"\
hannesw@1228 306 }\
hannesw@1228 307 ],\
hannesw@1228 308 "greeting": "Hello, Foreman Chaney! You have 5 unread messages.",\
hannesw@1228 309 "favoriteFruit": "strawberry"\
hannesw@1228 310 }\
hannesw@1228 311 ]';
hannesw@1228 312
hannesw@1228 313 for (var i = 0; i < 100; i++) {
hannesw@1228 314 bench();
hannesw@1228 315 }

mercurial