Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
Was your input file size the same all the time? Are you spooling the results to a file on local drive? Were you using the machine differently in each of the experiments (like may be you started a virus checker after the first run or something)? – NoChance May 5 '12 at 1:28
up vote 3 down vote accepted

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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