title: Why is it that Replacing File Reads with Memory Reads Doesn't Increase my Spring/Junit Test Performance?
body: <p>This is a spring boot project, we write our unit tests with junit. On my team, we save mock responses from downstream services in .json files and then parse those files into objects that we then use to track what the responses from those services should be. These are used in our junit tests. There are multiple files/objects in hundreds of unit tests that we have to consider for the mapping. They usually look like:</p>
  <pre><code>MyReturnObject obj = objectMapper.readValue(Files.readAllBytes(Paths.get(&quot;C:\\object.json&quot;)), MyReturnObject);
  </code></pre>
  <p>As you probably know, reads from disk are SLOW compared to reads from memory, and we do this over 200 times in one project. So, I wrote a python script that replaced all of those file reads with objects made using the .builder() annotation.</p>
  <pre><code>MyReturnObject.builder().value1(&quot;1&quot;).value2(&quot;2&quot;).value3(&quot;3&quot;).build(); 
  </code></pre>
  <p>And it didn't improve our Junit test performance even a little! I can't make heads or tails of what is going on, especially when all the evidence would point to this giving us even a slight performance boost, even like one second. I just did the same thing on my PC at home in two for loops (one for getting an object from memory and the other from a file) and the memory read was always 3 times as fast. Any ideas? I spent three days worth of work on this. The files are all saved in the /resources/ folder in Spring.</p>