{"ScriptPreparationCode":"function test(bin, bytes){\r\n\tvar r, i;\r\n\thex = \u0027\u0027, chars = \u0027\\n: -\u0027;\r\n\t//generate an array of random octets and\r\n\t//a corresponding hex string\r\n\tfor(i = 0; i \u003C bytes; i\u002B\u002B){\r\n\t\tr = Math.random() * 0x100 | 0,\r\n\t\tbin[i] = (r \u0026 0xff);\r\n\t\thex \u002B= (r \u003E\u003E 4).toString(16) \u002B (r \u0026 0xf).toString(16);\r\n\t}\r\n\t//insert non-hex characters at random positions in hex string\r\n\tfor(i = 0; i \u003C 10; i\u002B\u002B){\r\n\t\tr = Math.random() * hex.length | 0;\r\n\t\thex = hex.slice(0, r) \u002B chars.charAt(r \u0026 3) \u002B hex.slice(r);\r\n\t}\r\n return hex;\r\n}\r\n\r\nvar expected = [],\r\n testCase = test(expected, 10000);\r\n\r\nfunction parseHex1(hex){// original\r\n hex = hex.replace(/[^0-9a-fA-F]/g, \u0027\u0027);\r\n var i, \r\n len = hex.length, \r\n bin = [];\r\n for(i = 0; i \u003C len - 1; i \u002B= 2){\r\n bin.push(\u002B(\u00270x\u0027 \u002B hex.substring(i, i \u002B 2)));\r\n }\r\n return bin;\r\n}\r\n\r\nfunction parseHex2(string) {// replace match map ES5\r\n return string.replace(/[^0-9a-fA-F]/g, \u0027\u0027).match(/[0-9a-fA-F]{2}/g).map(function(hex) {\r\n return parseInt(hex, 16);\r\n });\r\n}\r\n\r\nfunction parseHex3(hex){//match without replace\r\n\t\thex = hex.match(/[\\da-f]/gi);\r\n\t\tfor(var i = 0; i \u003C hex.length - 1; i \u002B= 2){\r\n\t\t\thex[i \u003E\u003E 1] = \u002B(\u00270x\u0027 \u002B hex[i] \u002B hex[i \u002B 1]);\r\n\t\t}\r\n\t\thex.length = i \u003E\u003E 1;\r\n\t\treturn hex;\r\n}\r\n\r\n\r\nfunction parseHex4(hex){// iteration with replace\r\n \t\tvar bin = [];\r\n\t\thex.replace(/([\\da-f])[^\\da-f]*([\\da-f])/gi,\r\n\t\t\tfunction(m, digit1, digit2){\r\n\t\t\t\tbin.push(\u002B(\u00270x\u0027 \u002B digit1 \u002B digit2));\r\n\t\t\t}\r\n\t\t);\r\n\t\treturn bin;\r\n}\r\n\r\nfunction parseHex5(hex){// looping with exec\r\n\t\tvar bin = [],\r\n\t\t\tregex = /([\\da-f])[^\\da-f]*([\\da-f])/gi,\r\n\t\t\tresult;\r\n\t\twhile(result = regex.exec(hex)){\r\n\t\t\tbin.push(\u002B(\u00270x\u0027 \u002B result[1] \u002B result[2]));\r\n\t\t}\r\n\t\treturn bin;\r\n}\r\n\r\nfunction parseHex6(hex){// non regex\r\n\tvar bin = [], i, c, isEmpty = 1, buffer;\r\n\tfor(i = 0; i \u003C hex.length; i\u002B\u002B){\r\n\t\tc = hex.charCodeAt(i);\r\n\t\tif(c \u003E 47 \u0026\u0026 c \u003C 58 || c \u003E 64 \u0026\u0026 c \u003C 71 || c \u003E 96 \u0026\u0026 c \u003C 103){\r\n\t\t\tbuffer = buffer \u003C\u003C 4 ^ (c \u003E 64 ? c \u002B 9 : c) \u0026 15;\r\n\t\t\tif(isEmpty ^= 1){\r\n\t\t\t\tbin.push(buffer \u0026 0xff);\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\treturn bin;\r\n}\r\n","TestCases":[{"Name":"original","Code":"parseHex1(testCase);","IsDeferred":false},{"Name":"ES5 replace match map","Code":"parseHex2(testCase);","IsDeferred":false},{"Name":"match without replace","Code":"parseHex3(testCase);","IsDeferred":false},{"Name":"iteration with replace","Code":"parseHex4(testCase);","IsDeferred":false},{"Name":"looping with exec","Code":"parseHex5(testCase);","IsDeferred":false},{"Name":"non regex","Code":"parseHex6(testCase);","IsDeferred":false}]}