{"ScriptPreparationCode":null,"TestCases":[{"Name":"fast","Code":"function encode(string) {\r\n let pos = 0;\r\n const len = string.length;\r\n\r\n let at = 0; // output position\r\n let tlen = Math.max(32, len \u002B (len \u003E\u003E\u003E 1) \u002B 7); // 1.5x size\r\n let target = new Uint8Array((tlen \u003E\u003E\u003E 3) \u003C\u003C 3); // ... but at 8 byte offset\r\n\r\n while (pos \u003C len) {\r\n let value = string.charCodeAt(pos\u002B\u002B);\r\n if (value \u003E= 0xd800 \u0026\u0026 value \u003C= 0xdbff) {\r\n // high surrogate\r\n if (pos \u003C len) {\r\n const extra = string.charCodeAt(pos);\r\n if ((extra \u0026 0xfc00) === 0xdc00) {\r\n \u002B\u002Bpos;\r\n value = ((value \u0026 0x3ff) \u003C\u003C 10) \u002B (extra \u0026 0x3ff) \u002B 0x10000;\r\n }\r\n }\r\n if (value \u003E= 0xd800 \u0026\u0026 value \u003C= 0xdbff) {\r\n continue; // drop lone surrogate\r\n }\r\n }\r\n\r\n // expand the buffer if we couldn\u0027t write 4 bytes\r\n if (at \u002B 4 \u003E target.length) {\r\n tlen \u002B= 8; // minimum extra\r\n tlen *= (1.0 \u002B (pos / string.length) * 2); // take 2x the remaining\r\n tlen = (tlen \u003E\u003E\u003E 3) \u003C\u003C 3; // 8 byte offset\r\n\r\n const update = new Uint8Array(tlen);\r\n update.set(target);\r\n target = update;\r\n }\r\n\r\n if ((value \u0026 0xffffff80) === 0) { // 1-byte\r\n target[at\u002B\u002B] = value; // ASCII\r\n continue;\r\n } else if ((value \u0026 0xfffff800) === 0) { // 2-byte\r\n target[at\u002B\u002B] = ((value \u003E\u003E\u003E 6) \u0026 0x1f) | 0xc0;\r\n } else if ((value \u0026 0xffff0000) === 0) { // 3-byte\r\n target[at\u002B\u002B] = ((value \u003E\u003E\u003E 12) \u0026 0x0f) | 0xe0;\r\n target[at\u002B\u002B] = ((value \u003E\u003E\u003E 6) \u0026 0x3f) | 0x80;\r\n } else if ((value \u0026 0xffe00000) === 0) { // 4-byte\r\n target[at\u002B\u002B] = ((value \u003E\u003E\u003E 18) \u0026 0x07) | 0xf0;\r\n target[at\u002B\u002B] = ((value \u003E\u003E\u003E 12) \u0026 0x3f) | 0x80;\r\n target[at\u002B\u002B] = ((value \u003E\u003E\u003E 6) \u0026 0x3f) | 0x80;\r\n } else {\r\n continue; // out of range\r\n }\r\n\r\n target[at\u002B\u002B] = (value \u0026 0x3f) | 0x80;\r\n }\r\n\r\n // Use subarray if slice isn\u0027t supported (IE11). This will use more memory\r\n // because the original array still exists.\r\n return target.slice ? target.slice(0, at) : target.subarray(0, at);\r\n}\r\n\r\nfor (let i = 0; i \u003C 10000; i\u002B\u002B) {\r\n\tconst str = \u0027hi\u0027;\r\n \tencode(JSON.stringify(str));\r\n}","IsDeferred":false},{"Name":"google","Code":"function encode(str) {\r\n \u0027use strict\u0027;\r\n // TODO(user): Use native implementations if/when available\r\n var out = [], p = 0;\r\n for (var i = 0; i \u003C str.length; i\u002B\u002B) {\r\n var c = str.charCodeAt(i);\r\n if (c \u003C 128) {\r\n out[p\u002B\u002B] = c;\r\n } else if (c \u003C 2048) {\r\n out[p\u002B\u002B] = (c \u003E\u003E 6) | 192;\r\n out[p\u002B\u002B] = (c \u0026 63) | 128;\r\n } else if (\r\n ((c \u0026 0xFC00) == 0xD800) \u0026\u0026 (i \u002B 1) \u003C str.length \u0026\u0026\r\n ((str.charCodeAt(i \u002B 1) \u0026 0xFC00) == 0xDC00)) {\r\n // Surrogate Pair\r\n c = 0x10000 \u002B ((c \u0026 0x03FF) \u003C\u003C 10) \u002B (str.charCodeAt(\u002B\u002Bi) \u0026 0x03FF);\r\n out[p\u002B\u002B] = (c \u003E\u003E 18) | 240;\r\n out[p\u002B\u002B] = ((c \u003E\u003E 12) \u0026 63) | 128;\r\n out[p\u002B\u002B] = ((c \u003E\u003E 6) \u0026 63) | 128;\r\n out[p\u002B\u002B] = (c \u0026 63) | 128;\r\n } else {\r\n out[p\u002B\u002B] = (c \u003E\u003E 12) | 224;\r\n out[p\u002B\u002B] = ((c \u003E\u003E 6) \u0026 63) | 128;\r\n out[p\u002B\u002B] = (c \u0026 63) | 128;\r\n }\r\n }\r\n return out;\r\n};\r\n\r\nfor (let i = 0; i \u003C 10000; i\u002B\u002B) {\r\n\tconst str = \u0027hi\u0027;\r\n \tencode(JSON.stringify(str));\r\n}","IsDeferred":false},{"Name":"textencoder","Code":"const encoder = new TextEncoder();\r\n\r\nfor (let i = 0; i \u003C 10000; i\u002B\u002B) {\r\n\tconst str = \u0027hi\u0027;\r\n \tencoder.encode(JSON.stringify(str));\r\n}","IsDeferred":false}]}