考验大家电脑的时候到了

Sep 29th, 2007
    我将上次发布汉诺塔的代码稍加修改, 加入了能够计算运算花费时间的功能, 正好也可以测试cpu的运算能力, 已经在vista 和linux两个平台下进行测试

    2个平台分别是:

  • linux平台: Pm 1.4Ghz  512MB  suselinux 10.2
  • vista平台: amd 64位双核 3800+  2Ghz  2GB ddr,  vista32bit


linux平台下, 移动5个盘花费1秒, 10个1秒, 15个3秒,20个43秒,25个1325秒,30个40675秒(整整11个小时)
vista平台下, 移动5个盘花费2秒, 10个4秒, 15个20秒,20个293秒。

当然,我都不是在纯文本环境下进行的测试。 所以误差还是有的。如果是纯文本环境,个个平台应该更快。vista如果是64位,也应该不止如此表现。

代码如下:


<br/>#include &lt;iostream.h&gt;//towers of hanoi<br/>using namespace std;<br/><br/>int main()<br/>{<br/> &nbsp;///<br/> &nbsp;time_t before;<br/> &nbsp;time_t after;<br/> &nbsp;time (&amp;before);;<br/> &nbsp;//<br/> &nbsp;void towers(int n, char t1, char t2, char t3);<br/> &nbsp;int n;<br/> &nbsp;cout &lt;&lt; &quot;enter the number of disks:&quot;;<br/> &nbsp;cin &gt;&gt; n;<br/> &nbsp;int number;<br/> &nbsp;number = n;<br/> &nbsp;towers(n, &#039;A&#039;, &#039;B&#039;, &#039;C&#039;);<br/> &nbsp;time (&amp;after);<br/> &nbsp;cout &lt;&lt; endl &lt;&lt; &quot;There are &quot;&lt;&lt; number &lt;&lt; &quot; towers.&quot;; <br/> &nbsp;//<br/> &nbsp;cout &lt;&lt; endl &lt;&lt; before &lt;&lt; &quot; - &gt; &quot; &lt;&lt; after ;<br/> &nbsp;cout &lt;&lt; endl &lt;&lt; &quot;used &quot; &lt;&lt; after - before &nbsp;&lt;&lt; &quot; seconds&quot;;<br/>}<br/><br/>void towers(int n, char t1, char t2, char t3)<br/>{<br/> &nbsp;if(n &lt; 1) cout &lt;&lt; &quot;no disks&quot;;<br/> &nbsp;else if(n == 1) cout &lt;&lt;&quot;move top disk on tower &quot; &lt;&lt; t1 &lt;&lt; &quot; to tower &quot; &lt;&lt; t2 &lt;&lt; endl;<br/> &nbsp;else<br/> &nbsp;{<br/> &nbsp; &nbsp;towers(n-1, t1, t3, t2);<br/> &nbsp; &nbsp;cout &lt;&lt;&quot;move top disk on tower &quot; &lt;&lt; t1 &lt;&lt; &quot; to tower &quot; &lt;&lt; t2 &lt;&lt; endl;<br/> &nbsp; &nbsp;towers(n-1, t3, t2, t1);<br/> &nbsp;}<br/>}<br/>


也可以下载我编译好的执行文件,不过执行文件只能运行在windows平台下,linux可以下载代码用g++编译。

[file]attachment/200709/1191069359_0.rar[/file]

Share on Facebook
Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • email
  • Fleck
  • Gwar
  • Haohao
  • Identi.ca
  • laaik.it
  • LinkaGoGo
  • LinkedIn
  • Linkter
  • Live
  • MisterWong
  • MisterWong.DE
  • MSN Reporter
  • MySpace
  • PDF
  • Ping.fm
  • RSS
  • Slashdot
  • Socialogs
  • Technorati
  • Tumblr
  • Twitter
  • Twitthis
  • Webride
  • Yahoo! Bookmarks
  • Yigg
No comments yet.
Note: Commenter is allowed to use '@User+blank' to automatically notify your reply to other commenter. e.g, if ABC is one of commenter of this post, then write '@ABC '(exclude ') will automatically send your comment to ABC. Using '@all ' to notify all previous commenters. Be sure that the value of User should exactly match with commenter's name (case sensitive).