bytestohuman

JavaScript performance comparison

Test case created

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
switch
var bytesToHuman = function Helpers_bytesToHuman(bytes, precision) {
    var kb = 1024,
        mb = kb * 1024,
        gb = mb * 1024,
        tb = gb * 1024;

    switch (true) {
    case (bytes >= 0) && (bytes < kb):
      return bytes + ' B';
    case ((bytes >= kb) && (bytes < mb)):
      return (bytes / kb).toFixed(precision) + ' KB';
    case ((bytes >= mb) && (bytes < gb)):
      return (bytes / mb).toFixed(precision) + ' MB';
    case ((bytes >= gb) && (bytes < tb)):
      return (bytes / gb).toFixed(precision) + ' GB';
    case (bytes >= tb):
      return (bytes / tb).toFixed(precision) + ' TB';
    default:
      return bytes + ' B';
    }
    }
   
   
   
bytesToHuman(10000);
pending…
log
var bytesToHuman = function Helpers_countCapacity(b) {
    var u = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB'],
        m = Math,
        i = m.min(m.floor(m.log(b) / m.log(1024)), u.length - 1);
    return [parseFloat((b / m.pow(1024, i)).toFixed(2)) || 0, u[m.max(i, 0)]].join(' ').trim();
    }
   
   
   
bytesToHuman(10000);
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment