From 5a2357e551abe61cda4bf22019ea229d8ed0fb02 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Sat, 26 Jul 2014 01:24:22 +0200 Subject: jsrrdgraph: Performance fix commit 2a74a333ff143499b465234f0395a4aad7bdaa78 ("Upgrade to javascriptrrd ver 1.1.1") converted getByteAt calls to a getEndianByteAt call, but this also introduced a branch operation. Since endianess is dependent on the file, we can move the switch_endian check outside the function. Performance improved from 0.148ms (n=336k) to .039ms (n=384k) which translates to about 30 seconds! --- js/binaryXHR.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/js/binaryXHR.js b/js/binaryXHR.js index 63186b3..6749273 100644 --- a/js/binaryXHR.js +++ b/js/binaryXHR.js @@ -63,12 +63,15 @@ function BinaryFile(strData, iDataOffset, iDataLength) { throw new InvalidBinaryFile("Unsupported type " + (typeof strData)); } - this.getEndianByteAt = function(iOffset,width,delta) { - if (this.switch_endian) - return this.getByteAt(iOffset+width-delta-1); - else - return this.getByteAt(iOffset+delta); - }; + if (switch_endian) { + this.getEndianByteAt = function(iOffset, width, delta) { + return this.getByteAt(iOffset + width - delta - 1); + }; + } else { + this.getEndianByteAt = function(iOffset, width, delta) { + return this.getByteAt(iOffset + delta); + }; + } this.getLength = function() { return dataLength; -- cgit v1.1