2

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?

yannis
39.7k40 gold badges185 silver badges218 bronze badges
asked May 5, 2012 at 0:02
1
  • 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)? Commented May 5, 2012 at 1:28

1 Answer 1

3

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.

answered May 5, 2012 at 1:16

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.