1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Erlangのio:formatとio:fwriteに違いはあるか

Posted at

調べてもあまり出てこないけどErlang使いの中では常識...?

それともあまり気にされないのでしょうか

結論

おそらく、ない

理由

erlangcampでの io:fwrite vs. io:format への回答によればio.erlの内部でfwriteはformatにそのまま飛ばされていてただのAliasだとか。

確かめてみる

vim /usr/local/lib/erlang/lib/stdlib-2.2/src/io.erl
310 fwrite(Format) ->
311     format(Format).

...

317 fwrite(Format, Args) ->
318     format(Format, Args).

...

325 fwrite(Io, Format, Args) ->
326     format(Io, Format, Args).

確かに飛ばされてる

formatは

355 format(Format) ->
356     format(Format, []).

...

362 format(Format, Args) ->
363     format(default_output(), Format, Args).

...

370 format(Io, Format, Args) ->
371     o_request(Io, {format,Format,Args}, format).

ついでにdefault_output()も見てみる。

597 default_output() ->
598     group_leader().

余談

ではfwriteよりformatのほうが速いのか?

簡単な速度計測をしましたがこの差が有意かは怪しいところ...

試したのは以下の3つ

  1. format(group_leader(), format, [args])
  • format(format, [args])
  • fwrite(format, [args])

方法

10万回の出力を100セット、その平均で比較

結果

io Result(ms)
format gruop_leader() 987.38
format 1004.63
fwrite 1010.15
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?