Run details:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.116 Safari/537.36
Chrome 53
Windows
Other
8 years ago
Test name Executions per second
If and modulo array 549892.5 Ops/sec
Ternary and slice concatenation 628100.1 Ops/sec
Script Preparation code:
AخA
 
var z = 3661;
var t;
Tests:
  • If and modulo array

     
    var y = [];
    if (z>3600){
        y.push(Math.floor(z/3600));
    }
    z%=3600;
    if (z>60){
        y.push(Math.floor(z/60));
    }
    z%=60;
    if (z>0){
        y.push(Math.floor(z));
    }
    t = y.join(":").replace(/\b(\d)\b/g,"0$1");
  • Ternary and slice concatenation

     
    t = ("0"+Math.floor(z/3600).toString()).slice(-2)+":"+("0"+Math.floor(z%3600/60).toString()).slice(-2)+":"+("0"+Math.floor(z%3600%60).toString()).slice(-2)