2008年7月2日星期三

程式語言效率大比拼

有天正在尋找腳本語言的時候無意間發現這個名為 The Computer Language Benchmarks Game 的網站.
那裡的 benchmark 數據覆蓋多達 76 種語言加編輯器的組合, 19 個試驗程式(大部分還有提供源始碼).
不過, 儘管那裡提供的資料準確無誤, 它所包含的參考價值仍然有限. 問題在於那些試驗程式都過於細小, 以及只有單一的功能. 在一個複雜的應用程式 (如 3D Game Engine), 有大量不同種類的資料需要處理, 因此記憶體的存取很容易成為瓶頸.
一個好例子就是 Java/.Net. 有數據顯示 Java/.Net 可以快過 C/C++, 不過當你走出試驗程式返回現實, 你會感到 Java/.Net 總是慢半拍的.

其實那網站的第一段就表明了:
Benchmarking programming languages?
How can we benchmark a programming language?
We can't - we benchmark programming language implementations.

How can we benchmark language implementations?
We can't - we measure particular programs!

2 則留言:

  1. 同意,但有時C++的complie time 真的太慢了...

    另外,你對Script Language 的意見如何呢???最近我迷上了Python, Duck Typing 真的很方便,又不用compile...

    PS: 龍兄, 我有一個C++ 的問題,我有一些很差的方法,但想不到一個不用asm的方法,可以幫忙想想嗎?:

    Given a function :

    typedef int (*functor)();

    functor f(int i)
    {
    ...
    }

    How to implement f such that it will return a function returning i ?? and the signatures of functor and f cannot be changed...
    (but variable i must be smaller than N, which is a complie time constant)

    回覆刪除
  2. Hi, I also want to try Python/Ruby as the game scripting language. I think even the combination of pure C plus high level scripting language still a big win. So for my future development I may drift more code to the scripting side and kept C++ code stay at low-level as possible. I may have tons of question to ask you later on.
    By the way, I have answered your question as a new post, enjoy!

    回覆刪除