Should I prefer variables or multiple indirections on arrays in C# in perf critical code?

前端 未结 3 1289
再見小時候
再見小時候 2021-01-16 04:20

in some perf critical program (single threaded), if I have arrays of primitive types, and need to access the same index of those more than once in loops.

Should I us

3条回答
  •  情书的邮戳
    2021-01-16 05:11

    Array access always involves indirection, so if there are frequent accesses the variable will likely be faster.

    That said, I find it incredibly unlikely that you will be able to measure the difference. This is an example of micro-optimization.

提交回复
热议问题