Skip to content

println!でプレースホルダが増えるほど速度が遅くなるのでは #179

Description

@kumavale

例えば、println!("{}{}{}{}", i, i, i, i)の場合はWrite(string)が4回呼ばれる。

ldloca 1
call instance string int32::ToString()
call void [mscorlib]System.Console::Write(string)
ldloca 1
call instance string int32::ToString()
call void [mscorlib]System.Console::Write(string)
ldloca 1
call instance string int32::ToString()
call void [mscorlib]System.Console::Write(string)
ldloca 1
call instance string int32::ToString()
call void [mscorlib]System.Console::WriteLine(string)

Write,WriteLineの呼び出し回数が増えるほど遅くなるという先行研究(#175)があるので、一つの文字列にしてから1回だけWriteを呼ぶのが正解だと思う。

WriteLine(String.Concat(i.ToString(), i.ToString(), i.ToString(), i.ToString()));

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions