Help us understand the problem. What is going on with this article?

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

More than 5 years have passed since last update.

調べてもあまり出てこないけど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])
  2. format(format, [args])
  3. fwrite(format, [args])

方法

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

結果

io Result(ms)
format gruop_leader() 987.38
format 1004.63
fwrite 1010.15
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした