I want to generate a test scene for a unit-test (big file parser). What will be faster, to have a test file and to perform I/O on it, or to generate a large memory buffer using some static parameters during the compilation?

  • "or to generate a memory buffer during the compilation" If I understand you correctly, you would have some static data compiled into the code. How do you think that would affect the compilation process by means of performance? Your question doesn't make sense for me. – πάντα ῥεῖ Mar 18 '18 at 8:51
  • @πάνταῥεῖ not all the scene will be static. It will be generated using some static parameters. – Sanich Mar 18 '18 at 9:09

It depends.

If the generation code needs a lot of CPU cycles, using a file as a cache might bring performance benefits. If not, using a file as an intermediate storage can slow things down. The only sensible way to find out is try both and measure. The answer will also depend on your hardware & environment.

However, if you have two possible solutions at hand, start with the one which is easier to implement and check if it is quick enough for your purposes. If that is the case, there will probably no need to implement an even faster way.

Normally, I would expect the simpler solution to be a cache-free one. If that is true, I recommend to go that way, even if the other solution might be faster. Note when you introduce a file cache, you need to make sure you don't forget to update your file whenever the static parameter or the generation code changes, which means additional administrative overhead.

However, if you already have a lot of test data in form of files at hand, and don't need to write a generator for this data, then better try this solution first and check if it is fast enoough.

  • 2
    @Sanich: the file does not come from thin air, you will need some generator either. And this is not about an "exact way", it is is about a "sensible way", I used that attribut very intentionally. Without knowing "the real thing", the first solution could be 100 times faster than the second, or vice versa. – Doc Brown Mar 18 '18 at 9:23
  • Do you know why this question gets downvotes? From your answer a see that it is a legit question. How can I improve it? – Sanich Mar 18 '18 at 9:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.