fork(1) download
  1. <html>
  2. <head>
  3. <title></title>
  4. <script src="combination.js">
  5. </script>
  6. </head>
  7. <body>
  8. <script>
  9. n=5;
  10. document.write("recursive method:</br>");
  11. for(m=10;m<=20;m++)
  12. {
  13. if(m%2==0)
  14. n=m/2;
  15. //document.write("---------------------</br>");
  16. start=new Date();
  17. //document.write("m="+m+"n="+n+"</br>");
  18. ans1=recur_combi(m,n);
  19. //document.write("---------------------</br>");
  20. end=new Date();
  21. //document.write("---------------------</br>");
  22. time=end.getTime()-start.getTime();
  23. time=time/1000;
  24. document.write("recursive ans:"+ans1);
  25. document.write(" recursive time:"+time+"sec</br>");
  26.  
  27.  
  28. tbody=document.getElementbyId("t1");
  29. row=document.createElement("tr");
  30. col=document.createElement("td");
  31. value=document.createTextNode(m);
  32. col.appendChild(value);
  33. row.appendChild(col);
  34.  
  35. col=document.createElement("td");
  36. value=document.createTextNode(time);
  37. col.appendChild(value);
  38. row.appendChild(col);
  39.  
  40.  
  41.  
  42. //document.write(m+","+n);
  43. start=new Date();
  44. ans2=loop_combi(m,n);
  45. //document.write("loop ans:"+ans2);
  46. end=new Date();
  47. //document.write("loop ans:"+ans2);
  48. time=end.getTime()-start.getTime();
  49. document.write("loop ans:"+ans2);
  50. document.write(" loop time:"+time/1000+"sec</br>");
  51.  
  52. col=document.createElement("td");
  53. value=document.createTextNode(time/1000);
  54. col.appendChild(value);
  55. row.appendChild(col);
  56.  
  57.  
  58. tbody.appendChild(row);
  59. }
  60.  
  61. n=5;
  62. document.write("loop method:</br>");
  63. /*for(m=10;m<=20;m++)
  64. {
  65. if(m%2==0)
  66. n=m/2;
  67. start=new Date();
  68.   ans2=loop_combi(m,n);
  69. end=new Date();
  70. time=end.getTime()-start.getTime();
  71. document.write("loop ans:"+ans2);
  72. document.write(" loop time:"+time/1000+"sec</br>");
  73. col=document.createElement("td");
  74. value=document.createtextnode(time);
  75. n=m/2;
  76. }*/
  77. </script>
  78.  
  79. <table name="tab1">
  80. <tbody id="t1">
  81. <tr><th>m</th><th>遞迴方式</th><th>迴圈方式</th></tr>
  82. </tbody>
  83. </table>
  84. </body>
  85. </html>
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty