0

I want to hard code a giant array of integers in my program. I'm doing this because I want to benchmark a sorting algorithm. If I store the array as a text file and I read it in, then I will be measuring the performance of reading in a reading in a large file + sorting, rather than sorting alone. I'll be benchmarking file reading later. I could put int vals[] = {<huge number of values here>} directly into my main, but that tends to crash my text editor, so I was hoping there was some way to put in a separate file. My there's some way of #include'ing it? Is there a good way to do this?

J-bob
  • 8,380
  • 11
  • 52
  • 85
  • 3
    Why don't you just start the benchmark *after* the file is loaded? – Shomz Nov 25 '13 at 03:18
  • because it's being inserted into a large testing suite where the execution time of the entire executable is measured. It's a procedural script that is testing lots of files along with this one, so it's just measuring the whole run time. – J-bob Nov 25 '13 at 03:25

1 Answers1

0

You can create the array in a loop by applying some predictable logic. For instance, in one scenario you could iterate through the array and set the value to (size - index). You can get creative by using other functions like mod / multiple / xor, etc.

Nick
  • 4,002
  • 4
  • 30
  • 41