react-code-blocks
Issue #26

Recursive Example

e=>{const t=performance.now();let n=s[s.length-2],r=s[s.length-1],c=n+r;s.push(c),n=r,r=c,s.length<e&&l(e);return 1e3*(performance.now()-t)}
using dynamic text prop – will be minified post build

function recursive(arrLength) { var t0 = performance.now(); var firstNum = arr[arr.length - 2]; var secondNum = arr[arr.length - 1]; var nNum = firstNum + secondNum; arr.push(nNum); firstNum = secondNum; secondNum = nNum; if (arr.length < arrLength) { recursive(arrLength); } var t1 = performance.now(); return (t1 - t0) * 1000; }
using static text – will stay the same post build

Iterative Example

e=>{const t=performance.now();let n=[0,1];for(let r=n.length;r<e;r++){let e=n[n.length-1]+n[n.length-2];n.push(e)}return 1e3*(performance.now()-t)}
using dynamic text prop – will be minified post build

function iterative(arrLength) { var _loopIt = 0; var t0 = performance.now(); var arr = [0, 1]; for (var i = arr.length; i < arrLength; i++) { if (_loopIt++ > 10001) { var csb_global = typeof window === 'undefined' ? self : window; csb_global.infiniteLoopError = new RangeError('Potential infinite loop: exceeded ' + 10001 + ' iterations. You can disable this check by creating a sandbox.config.json file.'); throw csb_global.infiniteLoopError; } var nNum = arr[arr.length - 1] + arr[arr.length - 2]; arr.push(nNum); } var t1 = performance.now(); return (t1 - t0) * 1000; }
using static text – will stay the same post build