Re: [問題] 快速-九九乘法表
※ 引述《jeunder.bbs@ptt.cc》之銘言:
> 最簡單的方法, 沒有人想到嗎?
> 首先, i*j = j*i, 所以幾乎有一半不用算.
> 其次, i*(j+1) = i*j + i, 所以只要拿前一項 i*j 加上 i, 就得到 i*(j+1).
> 同理, (i+1)*j = i*j + j.
> 所以周圍的項目都可以用加法算出來, 而且只用 "一次" 加法.
> 依此類推擴展.
上個星期我試寫了一下這個做法,跟單純乘法比較,各跑10次
結果如下:
add: user:0.02 kern:0.03 clock:0.04 maxRes:434176K pfaults:1706 CPU%:111%
add: user:0.03 kern:0.01 clock:0.04 maxRes:434176K pfaults:1706 CPU%:90%
add: user:0.03 kern:0.01 clock:0.04 maxRes:434176K pfaults:1706 CPU%:93%
add: user:0.03 kern:0.01 clock:0.04 maxRes:434176K pfaults:1706 CPU%:95%
add: user:0.03 kern:0.03 clock:0.04 maxRes:434176K pfaults:1706 CPU%:125%
add: user:0.04 kern:0.00 clock:0.04 maxRes:434176K pfaults:1706 CPU%:97%
add: user:0.04 kern:0.01 clock:0.04 maxRes:434176K pfaults:1706 CPU%:116%
add: user:0.04 kern:0.02 clock:0.04 maxRes:434176K pfaults:1706 CPU%:133%
add: user:0.04 kern:0.02 clock:0.04 maxRes:434176K pfaults:1706 CPU%:139%
add: user:0.04 kern:0.02 clock:0.04 maxRes:434176K pfaults:1706 CPU%:142%
mul: user:0.03 kern:0.00 clock:0.04 maxRes:434176K pfaults:1706 CPU%:71%
mul: user:0.03 kern:0.01 clock:0.04 maxRes:434176K pfaults:1706 CPU%:90%
mul: user:0.03 kern:0.01 clock:0.04 maxRes:434176K pfaults:1706 CPU%:95%
mul: user:0.03 kern:0.01 clock:0.04 maxRes:434176K pfaults:1706 CPU%:95%
mul: user:0.03 kern:0.01 clock:0.04 maxRes:434176K pfaults:1706 CPU%:97%
mul: user:0.03 kern:0.03 clock:0.04 maxRes:434176K pfaults:1706 CPU%:150%
mul: user:0.04 kern:0.00 clock:0.04 maxRes:434176K pfaults:1706 CPU%:100%
mul: user:0.04 kern:0.02 clock:0.04 maxRes:434176K pfaults:1706 CPU%:142%
mul: user:0.04 kern:0.02 clock:0.04 maxRes:434176K pfaults:1706 CPU%:150%
mul: user:0.05 kern:0.01 clock:0.04 maxRes:434176K pfaults:1706 CPU%:136%
根本看不出什麼有意義的差別。Table大小是1000x1000,靜態配置,宣告在main()
以外,全域變數,用time算時間。後來我還動一點手腳,把尋找前一行同列cell
的運算簡化一點,拿掉乘法,改成減一個固定的offset就好,結果也沒啥差別。
前面那位每次可以跑到 0.3秒的,我在想是不是因為把動態記憶體配置的時間
也算進去的關係。
或者也可能是cygwin的time不準。總之後來我睡覺去了,因為我發現在這種超
簡單的operation 上偷時間實在是很無聊,還熬夜好幾個小時,更是無聊。
現在想到那天晚上還覺得浪費。 |<
--
蒙帝派松正體中文計畫 (4/23) - 如何隱身 - SPAM - 英國殺人笑話
http://www.wretch.cc/blog/journeyman&article_id=14377810
▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂
■法外科學暨工程顧問公司■ http://www.wretch.cc/blog/journeyman/
▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆
--
┌─────◆KKCITY◆─────┐ ● KKCITY 市民小常識 ●
│ bbs.kkcity.com.tw │ Q:文章標題前有#符號是代表什麼意思?
└──《From:59.115.208.128 》──┘ A:被作者加密了,需輸入密碼才能閱讀
--
推
05/27 14:36, , 1F
05/27 14:36, 1F
→
05/27 17:45, , 2F
05/27 17:45, 2F
→
05/27 17:45, , 3F
05/27 17:45, 3F
→
05/27 17:46, , 4F
05/27 17:46, 4F
→
05/27 17:49, , 5F
05/27 17:49, 5F
→
05/27 17:50, , 6F
05/27 17:50, 6F
討論串 (同標題文章)
完整討論串 (本文為第 7 之 10 篇):
1
6
Programming 近期熱門文章
PTT數位生活區 即時熱門文章