文字列型の指定

http://blog.bugyo.tk/lyrical/2009/03/cl-4.htmlのコメントの続き。

SBCLのソース(code/seq.lisp)をチラっと見てみたら、もしかしてvectorと指定した方が速い?と思って追試してみた。
ほぼ同じ内容のコード(ansiclのテキスト使った)をリピート回数2万回で型指定ナシ, string, vectorの3種を計測。
sbcl 1.0.26 (Mac OSX 10.5.5)にて

type - none
Evaluation took:
  1.536 seconds of real time
  1.522065 seconds of total run time (1.514246 user, 0.007819 system)
  99.09% CPU
  3,678,041,928 processor cycles
  0 bytes consed
  
type - string
Evaluation took:
  0.581 seconds of real time
  0.574724 seconds of total run time (0.572146 user, 0.002578 system)
  98.97% CPU
  1,389,602,664 processor cycles
  0 bytes consed
  
type - vector
Evaluation took:
  0.583 seconds of real time
  0.576425 seconds of total run time (0.573984 user, 0.002441 system)
  98.80% CPU
  1,395,920,700 processor cycles
  0 bytes consed

変わんなかった。が、Windows版だと

type - none
Evaluation took:
  1.594 seconds of real time
  1.578125 seconds of total run time (1.578125 user, 0.000000 system)
  99.00% CPU
  3,823,557,550 processor cycles
  0 bytes consed

type - string
Evaluation took:
  1.015 seconds of real time
  0.953125 seconds of total run time (0.953125 user, 0.000000 system)
  93.89% CPU
  2,425,093,589 processor cycles
  0 bytes consed

type - vector
Evaluation took:
  0.641 seconds of real time
  0.609375 seconds of total run time (0.609375 user, 0.000000 system)
  95.01% CPU
  1,531,308,100 processor cycles
  0 bytes consed

明らかにvectorを指定した方が速い。2byte文字だとダメってこともなさそうなんだけどダメな物もあるのかな。stringを使った方が行儀良いのだろうけど、気になる。

ちなみにClozure CLで試したら勝手に型推定してくれてるのか全部0.8秒弱だった。CLISPは全部18秒。

追記

NANRIさんに教えていただいたsimple-stringで (SBCL@Mac)

type - simple-string
Evaluation took:
  0.336 seconds of real time
  0.332874 seconds of total run time (0.332376 user, 0.000498 system)
  99.11% CPU
  802,959,588 processor cycles
  0 bytes consed

速くなった。SBCL@Winも

type - simple-string
Evaluation took:
  0.328 seconds of real time
  0.328125 seconds of total run time (0.328125 user, 0.000000 system)
  100.00% CPU
  800,258,714 processor cycles
  0 bytes consed