最速スクリプト言語決定戦!

このエントリーをはてなブックマークに追加
>>150
まくろって、つおい?

: nest { n d c }
  d 0 do
    n postpone literal 0 postpone literal postpone do
  loop
  c compile,
  d 0 do
    postpone loop
  loop
;

: nestedloop 0 [ 16 6 ' 1+ nest ] ;

nestedloop . cr


=> 0.010 / ruby 1.8.1 (2003-12-25) [powerpc-darwin]

16が即値で展開されるためさらに速くなった。
>>159
gforth-fast 0.6.2
でつ。
∩(´・ω・`)∩アゲトキマスネ
(´・ω・`)アガッテナイシ
163150:04/02/04 19:52
荒れてしまって申し訳ない。 >>159 さん自分は厨なので LISP も Forth もちゃんと触った
事はないので聞かれても…
>>151

def nested(n):
    x = 0
    i_r = range(n)
    for a in i_r:
        for b in i_r:
            for c in i_r:
                for d in i_r:
                    for e in i_r:
                        for f in i_r:
                            x += 1
    print x

じゃ駄目なの?

Python 2.3
=> 0.370 / ruby 1.8.1 (2003-12-25) [i386-mswin32]
165151:04/02/04 20:28
>>164
おいらが浅はかだっただけでつ(´・ω・`)
gforthはnative並の速さだな
もしかして実行時コンパイル?
>>166
コンパイル時実行、
・・とForth界隈では呼ばれています。マクロじゃなくて。
でもこの「コンパイル」っていうのは、ForthではVMコード
生成のことを言ってるわけで、ネイティブコード生成ではないです。
gforth自体はVMで動作してます。

168デフォルトの名無しさん:04/02/04 21:24
Forth ってすげぇ〜 VM 動作でこの速度かよ!! 恥ずかしながら
てっきり実行時にコンパイルしてるもんだと思ってた…

;; CMUCL で型指定付きでコンパイル
* (time (test))
; Evaluation took:
; 0.03 seconds of real time
; 0.023329 seconds of user run time
; 0.0 seconds of system run time
; 32,939,360 CPU cycles

;; インタプリタ起動時間込みでこれ.
$ time gforth-fast nest.f -e bye
16777216
gforth-fast nest.f -e bye 0.27s user 0.00s system 99% cpu 0.275 total
forth スゴイ
マジオススメ
と思ったけど日常生活で使うにはやはり厳しい…
cmuclはネイティブコンパイラですね。
ForthだとbigForthがネイティブコンパイルできるんですが、
まあ、スレ違いということで。。。。
ディスコンパイルすればちゃんとVMとして残ってるのがわかる。
see nestedloop
: nestedloop
0 <4212491> <16> 0
DO 16 0
DO 16 0
DO 16 0
DO 16 0
DO 16 0
DO 1+
LOOP
LOOP
LOOP
LOOP
LOOP
LOOP ; ok

ただしプリミティブを見るとnativeコードになってる
see 1+
Code 1+
( $401ABB ) inc ecx \ $41
( $401ABC ) add ebx , # 4 \ $83 $C3 $4
( $401ABF ) jmp dword ptr FC [ebx] \ $FF $63 $FC
end-code

この最後の2行に注目すると、
( $401ABC ) add ebx , # 4 \ $83 $C3 $4
( $401ABF ) jmp dword ptr FC [ebx] \ $FF $63 $FC

direct threaderd codeという方法を使ってるのがわかる。(ebxがpcに相当)
綴り間違えた
s/threaderd/threaded/
173159:04/02/04 21:49
ちなみにgforth0.6以降は、

>New threaded code execution method: primitive-centric (allows the following),
>hybrid direct/indirect threaded (easier portability), with dynamic superinstructions
> (typical speedup on Athlon: factor 2).

と書かれていてprimitive-centricという新しい手法を使っているらしい。
(詳細不明。。)
正直、動的型な言語だとまず型チェックとか入るから
いきなりinc ecxとか実行でけるforthがうらやましい。
つーことはecx何某はスタックトップの演算ということかな。
(あんま知らないので間違ってたらすまそ)
ecxはレジスタらしいね。
スタックトップ(TOS)をレジスタに割り当てるのはVMの高速化の常法。