Skip to main content
Edited formatting for leaderboard
Source Link
Beta Decay
  • 23.4k
  • 8
  • 72
  • 165

JavascriptJavaScript ES6, 40 bytes

t=>{for(t=(d=Date.now)()+t*1e3;d()<t;);}

Tested with the following:

elapsed=(f,t,b=(d=Date.now)())=>(f(t),console.log(d()-b+"ms elapsed")) // accepts func, delay
STOP=t=>{for(t=(d=Date.now)()+t*1e3;d()<t;);}
elapsed(STOP,1)  // prints 1000ms elapsed
elapsed(STOP,5)  // prints 5000ms elapsed
elapsed(STOP,25) // prints 25000ms elapsed

Javascript ES6, 40 bytes

t=>{for(t=(d=Date.now)()+t*1e3;d()<t;);}

Tested with the following:

elapsed=(f,t,b=(d=Date.now)())=>(f(t),console.log(d()-b+"ms elapsed")) // accepts func, delay
STOP=t=>{for(t=(d=Date.now)()+t*1e3;d()<t;);}
elapsed(STOP,1)  // prints 1000ms elapsed
elapsed(STOP,5)  // prints 5000ms elapsed
elapsed(STOP,25) // prints 25000ms elapsed

JavaScript ES6, 40 bytes

t=>{for(t=(d=Date.now)()+t*1e3;d()<t;);}

Tested with the following:

elapsed=(f,t,b=(d=Date.now)())=>(f(t),console.log(d()-b+"ms elapsed")) // accepts func, delay
STOP=t=>{for(t=(d=Date.now)()+t*1e3;d()<t;);}
elapsed(STOP,1)  // prints 1000ms elapsed
elapsed(STOP,5)  // prints 5000ms elapsed
elapsed(STOP,25) // prints 25000ms elapsed
Source Link
Dendrobium
  • 2.5k
  • 12
  • 25

Javascript ES6, 40 bytes

t=>{for(t=(d=Date.now)()+t*1e3;d()<t;);}

Tested with the following:

elapsed=(f,t,b=(d=Date.now)())=>(f(t),console.log(d()-b+"ms elapsed")) // accepts func, delay
STOP=t=>{for(t=(d=Date.now)()+t*1e3;d()<t;);}
elapsed(STOP,1)  // prints 1000ms elapsed
elapsed(STOP,5)  // prints 5000ms elapsed
elapsed(STOP,25) // prints 25000ms elapsed