Faster way to zero memory than with memset?

后端 未结 9 1478
刺人心
刺人心 2020-12-07 12:02

I learned that memset(ptr, 0, nbytes) is really fast, but is there a faster way (at least on x86)?

I assume that memset uses mov, however w

9条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-07 12:40

    There is one fatal flaw in this otherwise great and helpful test: As memset is the first instruction, there seems to be some "memory overhead" or so which makes it extremely slow. Moving the timing of memset to second place and something else to first place or simply timing memset twice makes memset the fastest with all compile switches!!!

提交回复
热议问题