Why is memcpy slower than a reinterpret_cast when parsing binary data?

前端 未结 3 1761
迷失自我
迷失自我 2020-12-31 12:25

TLDR: I forgot to enable compiler optimizations. With the optimizations enabled the performance is (nearly) identical.


Original post

When r

3条回答
  •  情歌与酒
    2020-12-31 12:56

    memcpy cannot copy to a register, it does a memory-to-memory copy. The reinterpret_cast in get_int_v1 can change the type of pointer held in a register, and that doesn't even require a register-to-register copy.

提交回复
热议问题