震驚的消息 : AS3 int/uint 比 Number 還慢
在一般的觀念裏,int/uint 比較省memory,複雜度比較低處理起來也比較快,因此當 AS3 一出來後,大部份人都將 Number 改成 int/uint。
但今天 Sho 跟 Grant Skinner 的測試結果讓人震驚,他們發現在 AS3裏,效率是 Number > int > uint。
在sho的報導裏提到可能的原因:
ECMAScript Edition 4 裏為了向下相容(backward compatibility),因此內部運算是仍然是用 Number 來進行,這代表 int/uint 必需先轉換成 Number 再進行處理,然後最後再轉回 int/uint,這種不必要的轉換就是拖慢速度的原因。
另外,他也提到 Number 內部的 precision 比 int高,因為它同時兼俱下列三者的特性:
* int
* uint
* IEEE double
所以如果有人想用 AS3 算 DNA的話,最好還是乖乖用 Number。
至於我呢,得開始把所有程式拿出來 find and replace all了,唉~
最後,這件事的兩個教訓:
1、trust no “granted”: 每當程式語言有新版本出現時,別天真的相信新功能一定比較好比較強,要不斷的做 benchmark testing。
2、要多看blog啊~
by admin


12 Comments Add your own
1. cmanwalking&hellip | June 17th, 2006 at 11:27 am
不好意思,想请教:Number > int > uint具体是什么东西?单纯的数据格式么?如果不麻烦的话,请给个详细的说明。
2. shen14&hellip | June 17th, 2006 at 11:40 am
你可以参看下楼主给的链接阿
3. jeremy&hellip | June 17th, 2006 at 11:42 am
AS3 的手冊裏有關於 int, uint, Number 三者的詳細解釋,簡單來說:
Number: 可有浮點,例如 123.456789
int: -123, 123 含正負號的整數
uint: 123 不能有負號的整號
如果想瞭解在一般程式語言這三者的意義,可以看 wiki 上的解釋:
http://en.wikipedia.org/wiki/Int
只是在這個bechmark 出來後,它們的差異再也不重要了,就是乖乖用 Number 了…
4. Dreamer&hellip | June 17th, 2006 at 7:08 pm
我现在都用int~因为感觉比较直观~~现在看来得改了
5. cmanwalking&hellip | June 18th, 2006 at 8:48 am
哈,有些明白了.谢谢啊
http://en.wikipedia.org/wiki/Int
好像这个在我这儿打不开.
另:MYSQL的数据类型好像没有NUMBER\UNIT…
6. jeremy&hellip | June 18th, 2006 at 10:32 am
wiki 那頁看不到沒什麼關係,看flex 手冊上的解釋也很夠了。
mysql 有 int, bigint, interger…. 等五六種 type啊。
7. miao&hellip | June 18th, 2006 at 11:00 am
打不开?跟俺一样也在mainland说
8. cmanwalking&hellip | June 18th, 2006 at 2:18 pm
知道了,谢谢前辈这么耐心的答复啊。
9. miao&hellip | June 19th, 2006 at 7:49 pm
http://www.flashanywhere.net/mxna/index.cfm
前辈,这个怎么都在链您的?
10. jeremy&hellip | June 19th, 2006 at 11:03 pm
呃 我也不知道,或許它是設定每星期抓一次 feed ? 所以每星期一就會把上週所有文章抓去導致版面都是我的文章?
11. gourry&hellip | August 13th, 2008 at 5:05 pm
請問在Flex3也是一樣的情形嗎?
還是說在Flex3中已改善了
12. admin&hellip | August 13th, 2008 at 7:38 pm
flex 3 是用 as3 寫的,所以肯定沒改善。
只能等 as4 出來再看看了。
Trackback this post | Subscribe to the comments via RSS Feed