Openbravo Issue Tracking System - Retail Modules
View Issue Details
0029696Retail ModulesWeb POSpublic2015-04-24 15:582015-04-24 15:58
Orekaria 
Retail 
normalminoralways
newopen 
5
 
 
No
0029696: Add a sizeOf method to be able to know the size of the objects
Add a sizeOf method to be able to know the size of the objects

This is useful to analyze user installations
verify that the new method can calculate the size of the OB object
Something like this:


      var memorySizeOf = function(obj) {
          var bytes = 0;

          function sizeOf(obj) {
              if(obj !== null && obj !== undefined) {
                  switch(typeof obj) {
                  case 'number':
                      bytes += 8;
                      break;
                  case 'string':
                      bytes += obj.length * 2;
                      break;
                  case 'boolean':
                      bytes += 4;
                      break;
                  case 'object':
                      var objClass = Object.prototype.toString.call(obj).slice(8, -1);
                      if(objClass === 'Object' || objClass === 'Array') {
                          for(var key in obj) {
                              if(!obj.hasOwnProperty(key)) continue;
                              sizeOf(obj[key]);
                          }
                      } else bytes += obj.toString().length * 2;
                      break;
                  }
              }
              return bytes;
          }

          function formatByteSize(bytes) {
              if(bytes < 1024) return bytes + " bytes";
              else if(bytes < 1048576) return(bytes / 1024).toFixed(2) + " KiB";
              else if(bytes < 1073741824) return(bytes / 1048576).toFixed(2) + " MiB";
              else return(bytes / 1073741824).toFixed(2) + " GiB";
          }

          return formatByteSize(sizeOf(obj));
      };
No tags attached.
Issue History
2015-04-24 15:58OrekariaNew Issue
2015-04-24 15:58OrekariaAssigned To => Retail
2015-04-24 15:58OrekariaTriggers an Emergency Pack => No

There are no notes attached to this issue.