标签:blog http io 使用 ar java for 2014 on
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>每天一个JavaScript实例-使用缓存计算(memoization)来提高应用程序性能</title> <script> window.onload = function(){ var fibonacci = function(){ var memo = [0,1]; var fib = function(n){ var result = memo[n]; if(typeof result != "number"){ result = fib(n-1) + fib(n-2); memo[n] = result; } console.log("memo"+memo); return result; }; return fib; }(); var fib =function(n){ return n<2?n:fib(n-1)+fib(n-2); }; console.time("non-memo"); for(var i = 0; i<=10;i++){ console.log(i+ " " + fib(i)); } console.timeEnd("non-memo"); console.time("memo"); for(var i = 0; i<=10;i++){ console.log(i+ " " + fibonacci(i) ); } console.timeEnd("memo"); } </script> </head> <body> </body> </html>
每天一个JavaScript实例-使用缓存计算(memoization)来提高应用程序性能
标签:blog http io 使用 ar java for 2014 on
原文地址:http://blog.csdn.net/waiting7436/article/details/40144027