{"ScriptPreparationCode":" var totalValues = 1024 * 1024;\r\n\tvar valueSize = 8;\r\n\tvar totalBytes = totalValues * valueSize;\r\n\tvar buffer = new ArrayBuffer(totalBytes);\r\n\t// fill\r\n\tvar dv = new DataView(buffer);\r\n\tfor (i=0; i\u003CtotalBytes; i\u002B=valueSize) {\r\n\t num = Math.random()*1000;\r\n\t if (Math.random() \u003C 0.5) num *= -1;\r\n\t dv.setFloat64(i,num,true);\r\n\t}\r\n\t\t\t\r\n\t\r\nBinaryParser = function(bigEndian, allowExceptions){\r\n this.bigEndian = bigEndian, this.allowExceptions = allowExceptions;\r\n};\r\nwith({p: BinaryParser.prototype}){\r\n p.encodeFloat = function(number, precisionBits, exponentBits){\r\n var bias = Math.pow(2, exponentBits - 1) - 1, minExp = -bias \u002B 1, maxExp = bias, minUnnormExp = minExp - precisionBits,\r\n status = isNaN(n = parseFloat(number)) || n == -Infinity || n == \u002BInfinity ? n : 0,\r\n exp = 0, len = 2 * bias \u002B 1 \u002B precisionBits \u002B 3, bin = new Array(len),\r\n signal = (n = status !== 0 ? 0 : n) \u003C 0, n = Math.abs(n), intPart = Math.floor(n), floatPart = n - intPart,\r\n i, lastBit, rounded, j, result;\r\n for(i = len; i; bin[--i] = 0);\r\n for(i = bias \u002B 2; intPart \u0026\u0026 i; bin[--i] = intPart % 2, intPart = Math.floor(intPart / 2));\r\n for(i = bias \u002B 1; floatPart \u003E 0 \u0026\u0026 i; (bin[\u002B\u002Bi] = ((floatPart *= 2) \u003E= 1) - 0) \u0026\u0026 --floatPart);\r\n for(i = -1; \u002B\u002Bi \u003C len \u0026\u0026 !bin[i];);\r\n if(bin[(lastBit = precisionBits - 1 \u002B (i = (exp = bias \u002B 1 - i) \u003E= minExp \u0026\u0026 exp \u003C= maxExp ? i \u002B 1 : bias \u002B 1 - (exp = minExp - 1))) \u002B 1]){\r\n if(!(rounded = bin[lastBit]))\r\n for(j = lastBit \u002B 2; !rounded \u0026\u0026 j \u003C len; rounded = bin[j\u002B\u002B]);\r\n for(j = lastBit \u002B 1; rounded \u0026\u0026 --j \u003E= 0; (bin[j] = !bin[j] - 0) \u0026\u0026 (rounded = 0));\r\n }\r\n for(i = i - 2 \u003C 0 ? -1 : i - 3; \u002B\u002Bi \u003C len \u0026\u0026 !bin[i];);\r\n\r\n (exp = bias \u002B 1 - i) \u003E= minExp \u0026\u0026 exp \u003C= maxExp ? \u002B\u002Bi : exp \u003C minExp \u0026\u0026\r\n (exp != bias \u002B 1 - len \u0026\u0026 exp \u003C minUnnormExp \u0026\u0026 this.warn(\u0022encodeFloat::float underflow\u0022), i = bias \u002B 1 - (exp = minExp - 1));\r\n (intPart || status !== 0) \u0026\u0026 (this.warn(intPart ? \u0022encodeFloat::float overflow\u0022 : \u0022encodeFloat::\u0022 \u002B status),\r\n exp = maxExp \u002B 1, i = bias \u002B 2, status == -Infinity ? signal = 1 : isNaN(status) \u0026\u0026 (bin[i] = 1));\r\n for(n = Math.abs(exp \u002B bias), j = exponentBits \u002B 1, result = \u0022\u0022; --j; result = (n % 2) \u002B result, n = n \u003E\u003E= 1);\r\n for(n = 0, j = 0, i = (result = (signal ? \u00221\u0022 : \u00220\u0022) \u002B result \u002B bin.slice(i, i \u002B precisionBits).join(\u0022\u0022)).length, r = [];\r\n i; n \u002B= (1 \u003C\u003C j) * result.charAt(--i), j == 7 \u0026\u0026 (r[r.length] = String.fromCharCode(n), n = 0), j = (j \u002B 1) % 8);\r\n r[r.length] = n ? String.fromCharCode(n) : \u0022\u0022;\r\n return (this.bigEndian ? r.reverse() : r).join(\u0022\u0022);\r\n };\r\n p.encodeInt = function(number, bits, signed){\r\n var max = Math.pow(2, bits), r = [];\r\n (number \u003E= max || number \u003C -(max \u003E\u003E 1)) \u0026\u0026 this.warn(\u0022encodeInt::overflow\u0022) \u0026\u0026 (number = 0);\r\n number \u003C 0 \u0026\u0026 (number \u002B= max);\r\n for(; number; r[r.length] = String.fromCharCode(number % 256), number = Math.floor(number / 256));\r\n for(bits = -(-bits \u003E\u003E 3) - r.length; bits--; r[r.length] = \u0022\\0\u0022);\r\n return (this.bigEndian ? r.reverse() : r).join(\u0022\u0022);\r\n };\r\n p.decodeFloat = function(data, precisionBits, exponentBits){\r\n var b = ((b = new this.Buffer(this.bigEndian, data)).checkBuffer(precisionBits \u002B exponentBits \u002B 1), b),\r\n bias = Math.pow(2, exponentBits - 1) - 1, signal = b.readBits(precisionBits \u002B exponentBits, 1),\r\n exponent = b.readBits(precisionBits, exponentBits), significand = 0,\r\n divisor = 2, curByte = b.buffer.length \u002B (-precisionBits \u003E\u003E 3) - 1,\r\n byteValue, startBit, mask;\r\n do\r\n for(byteValue = b.buffer[ \u002B\u002BcurByte ], startBit = precisionBits % 8 || 8, mask = 1 \u003C\u003C startBit;\r\n mask \u003E\u003E= 1; (byteValue \u0026 mask) \u0026\u0026 (significand \u002B= 1 / divisor), divisor *= 2);\r\n while(precisionBits -= startBit);\r\n return exponent == (bias \u003C\u003C 1) \u002B 1 ? significand ? NaN : signal ? -Infinity : \u002BInfinity\r\n : (1 \u002B signal * -2) * (exponent || significand ? !exponent ? Math.pow(2, -bias \u002B 1) * significand\r\n : Math.pow(2, exponent - bias) * (1 \u002B significand) : 0);\r\n };\r\n p.decodeInt = function(data, bits, signed){\r\n var b = new this.Buffer(this.bigEndian, data), x = b.readBits(0, bits), max = Math.pow(2, bits);\r\n return signed \u0026\u0026 x \u003E= max / 2 ? x - max : x;\r\n };\r\n with({p: (p.Buffer = function(bigEndian, buffer){\r\n this.bigEndian = bigEndian || 0, this.buffer = [], this.setBuffer(buffer);}).prototype}){\r\n p.readBits = function(start, length){\r\n //shl fix: Henri Torgemane ~1996 (compressed by Jonas Raoni)\r\n function shl(a, b){\r\n for(\u002B\u002Bb; --b; a = ((a %= 0x7fffffff \u002B 1) \u0026 0x40000000) == 0x40000000 ? a * 2 : (a - 0x40000000) * 2 \u002B 0x7fffffff \u002B 1);\r\n return a;\r\n }\r\n if(start \u003C 0 || length \u003C= 0)\r\n return 0;\r\n this.checkBuffer(start \u002B length);\r\n for(var offsetLeft, offsetRight = start % 8, curByte = this.buffer.length - (start \u003E\u003E 3) - 1,\r\n lastByte = this.buffer.length \u002B (-(start \u002B length) \u003E\u003E 3), diff = curByte - lastByte,\r\n sum = ((this.buffer[ curByte ] \u003E\u003E offsetRight) \u0026 ((1 \u003C\u003C (diff ? 8 - offsetRight : length)) - 1))\r\n \u002B (diff \u0026\u0026 (offsetLeft = (start \u002B length) % 8) ? (this.buffer[ lastByte\u002B\u002B ] \u0026 ((1 \u003C\u003C offsetLeft) - 1))\r\n \u003C\u003C (diff-- \u003C\u003C 3) - offsetRight : 0); diff; sum \u002B= shl(this.buffer[ lastByte\u002B\u002B ], (diff-- \u003C\u003C 3) - offsetRight)\r\n );\r\n return sum;\r\n };\r\n p.setBuffer = function(data){\r\n if(data instanceof Object){\r\n for(var l, i = l = data.length, b = this.buffer = new Array(l); i; b[l - i] = data[--i]);\r\n this.bigEndian \u0026\u0026 b.reverse();\r\n }\r\n if(data instanceof String){\r\n for(var l, i = l = data.length, b = this.buffer = new Array(l); i; b[l - i] = data.charCodeAt(--i));\r\n this.bigEndian \u0026\u0026 b.reverse();\r\n }\r\n };\r\n p.hasNeededBits = function(neededBits){\r\n return this.buffer.length \u003E= -(-neededBits \u003E\u003E 3);\r\n };\r\n p.checkBuffer = function(neededBits){\r\n if(!this.hasNeededBits(neededBits))\r\n throw new Error(\u0022checkBuffer::missing bytes\u0022);\r\n };\r\n }\r\n p.warn = function(msg){\r\n if(this.allowExceptions)\r\n throw new Error(msg);\r\n return 1;\r\n };\r\n p.toSmall = function(data){return this.decodeInt(data, 8, true);};\r\n p.fromSmall = function(number){return this.encodeInt(number, 8, true);};\r\n p.toByte = function(data){return this.decodeInt(data, 8, false);};\r\n p.fromByte = function(number){return this.encodeInt(number, 8, false);};\r\n p.toShort = function(data){return this.decodeInt(data, 16, true);};\r\n p.fromShort = function(number){return this.encodeInt(number, 16, true);};\r\n p.toWord = function(data){return this.decodeInt(data, 16, false);};\r\n p.fromWord = function(number){return this.encodeInt(number, 16, false);};\r\n p.toInt = function(data){return this.decodeInt(data, 32, true);};\r\n p.fromInt = function(number){return this.encodeInt(number, 32, true);};\r\n p.toDWord = function(data){return this.decodeInt(data, 32, false);};\r\n p.fromDWord = function(number){return this.encodeInt(number, 32, false);};\r\n p.toFloat = function(data){return this.decodeFloat(data, 23, 8);};\r\n p.fromFloat = function(number){return this.encodeFloat(number, 23, 8);};\r\n p.toDouble = function(data){return this.decodeFloat(data, 52, 11);};\r\n p.fromDouble = function(number){return this.encodeFloat(number, 52, 11);};\r\n}\r\n\r\n\r\ndoubble=new BinaryParser(false,true);\r\nvar seek=0;\r\nvar stream = new Uint8Array(buffer);\r\n\r\nfunction readDouble(stream){\r\n var bytes=stream.subarray(seek,seek\u002B8);\r\n seek=seek\u002B8;\r\n return doubble.toDouble(bytes);\r\n}\r\n","TestCases":[{"Name":"Dataview","Code":"for (i=0; i\u003CtotalBytes; i\u002B=valueSize) {\r\n num = dv.getFloat64(i,true);\t \r\n}","IsDeferred":false},{"Name":"Custom","Code":"for (i=0; i\u003CtotalBytes; i\u002B=valueSize) {\r\n num = readDouble(stream);\t \r\n}","IsDeferred":false},{"Name":"Basecase - Just loop","Code":"for (i=0; i\u003CtotalBytes; i\u002B=valueSize) { \r\n}","IsDeferred":false}]}