Skip to content

Instantly share code, notes, and snippets.

@melnik88
Created September 1, 2016 18:15
Show Gist options
  • Save melnik88/edb162dd24014e3db110fca2876affe2 to your computer and use it in GitHub Desktop.
Save melnik88/edb162dd24014e3db110fca2876affe2 to your computer and use it in GitHub Desktop.
Измерение производительности javascript-функций
function fib3(value){
if(value === 1) return 1
if(value === 2) return 1
if(value > 2) {
return fib3(value - 1 ) + fib3(value - 2)
}
}
let t0 = performance.now();
result = fib3(30);
let t1 = performance.now();
console.log('Took', (t1 - t0).toFixed(4), 'milliseconds to generate:', result);
function fib(value) {
function fib2(value, k, fk, fk1){
if(k==value) return fk
if(k < value){
return fib2(value, k+1, fk+fk1, fk)
}
}
if(value == 1) return 1;
return fib2(value, 2, 1, 1);
}
t0 = performance.now();
result = fib(30);
t1 = performance.now();
console.log('Took', (t1 - t0).toFixed(4), 'milliseconds to generate:', result);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment