看板Programming
标 题Re: [问题] 快速-九九乘法表
发信站KKCITY (Tue May 27 11:15:14 2008)
转信站ptt!ctu-reader!ctu-gate!news.nctu!news.ncu!news.yzu!zoonews.ee.ntu!new
※ 引述《[email protected]》之铭言:
> 最简单的方法, 没有人想到吗?
> 首先, 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:被作者加密了,需输入密码才能阅读
--
1F:推 kbslave:我深感抱歉~~!@@ 140.114.71.150 05/27 14:36
2F:→ MOONRAKER:不用抱歉吧 XD 大家都是有兴趣才钻进去 59.115.216.75 05/27 17:45
3F:→ MOONRAKER:不过钻进去venture之後却发现不怎麽有趣 59.115.216.75 05/27 17:45
4F:→ MOONRAKER:顶多就是当成自己投资错误 XD 59.115.216.75 05/27 17:46
5F:→ MOONRAKER:而且没实作一次,谁知道现在偷时间已经 59.115.216.75 05/27 17:49
6F:→ MOONRAKER:没有这麽单纯的了? 59.115.216.75 05/27 17:50