fibo-algo (v14)

Revision 14 of this benchmark created by Johnson Chen on


Preparation HTML

<script>
function fiboLoop(num){
  var a = 1, b = 0, temp;

  while (num >= 0){
    temp = a;
    a = a + b;
    b = temp;
    num--;
  }

  return b;
}

function fiboRec(num) {
  if (num <= 1) return 1;

  return fiboRec(num - 1) + fiboRec(num - 2);
}

function fiboRec2(index, prev = 0, curr = 1){
	if (index > 1){
  	return f(index - 1, curr, prev+curr);
  }
  else {
  	return curr;
  }
}

function fiboMemo(num, memo) {
  memo = memo || {};

  if (memo[num]) return memo[num];
  if (num <= 1) return 1;

  return memo[num] = fiboMemo(num - 1, memo) + fiboMemo(num - 2, memo);
}
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Rec
fiboRec(1000000)
ready
Loop
fiboLoop(1000000)
ready
Mem
fiboMemo(1000000)
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.

  • Revision 1: published by Hector Zarco on
  • Revision 10: published by Stephen Turner on
  • Revision 14: published by Johnson Chen on