# How to use std.mem.doNotOptimizeAway?

**URL:** <https://ziggit.dev/t/how-to-use-std-mem-donotoptimizeaway/4677>\
**Category:** Explain\
**Tags:** standard-library\
**Created:** [June 10, 2024, 3:00am UTC](https://ziggit.dev/t/how-to-use-std-mem-donotoptimizeaway/4677 "2024-06-10T03:00:57Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sze](https://ziggit.dev/user_avatar/ziggit.dev/sze/32/496_2.png) [@Sze](https://ziggit.dev/u/Sze)\
**Post date:** [June 10, 2024, 3:00am UTC](https://ziggit.dev/t/how-to-use-std-mem-donotoptimizeaway/4677/1 "2024-06-10T03:00:57Z")

</div>

How to use `std.mem.doNotOptimizeAway()`?

- It seems like projects apply the function to an output  
value of the benchmark, that output value is an  
accumulator of the intermediaries of what is being  
benchmarked, for example it could be a sum of calculated values

- how does it work?  
it creates an asm block that looks opaque for the compiler  
so that it has to assume that it can’t optimize the result away?

This is just a bit of what I had already, if you have corrections better explanaitions those are of course welcome.
