I have a very simple program in Ruby that opens a dictionary file, sorted-words.txt and prints out all the words in pig-latin. I tested its speed, and the first time I ran it, the program finished in about 1.6 seconds. The second time I ran the program, it took about 2.1 seconds. Between the two runs, there was maybe about a 10 second wait, me looking at the results and running the program again. I waited a minute, ran it again, and it ran in 1.8 seconds. Although the variation is slight, it is still there. Why is there this variation?
File Processing Times
optimization;file handling;speed;files
Variations like that are typically due to Operating System and hardware variance.In the Operating System, it runs processes like your program on a time shared basis so that even for a very small and simple program the multitasking of background programs will slightly affect the results.On a hardware level you've several things going on but mostly it's file I/O. In file I/O the program loads to RAM, then communicates with the CPU which is multitasking. It then has to send to, wait and receive from the hard drive. Since the Hard Drive is a sequential device, you have variances in access and read time since it may not be in the same place every time. To test this, get a solid state drive and a standard hard drive and test them in the same system. There should be less variance in the Solid State system. If not, it's some other issue.