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