How performant is StackFrame?

前端 未结 7 1225
鱼传尺愫
鱼传尺愫 2020-12-01 02:18

I am considering using something like StackFrame stackFrame = new StackFrame(1) to log the executing method, but I don\'t know about its performance implication

7条回答
  •  一向
    一向 (楼主)
    2020-12-01 02:33

    I think Paul Williams hit the nail on the head with the work being done. If you dig deeper into StackFrameHelper you'll find that fNeedFileInfo is actually the performance killer - especially in debug mode. Try setting it false if performance is important. You won't get much useful information in release mode anyway.

    If you pass false in here you'll still get method names when doing a ToString() and without outputting any information, just moving stack pointers around, it's very fast.

提交回复
热议问题