0

When I run for example (time ./sort1 random5000.txt) it gives me real, syst, and user time. But if I run the same command again it will gives me different time results! I can't understand why this scenario happens. Knowing that this difference doesn't follow certain pattern, sometimes time increased and other time it deceased.

0

If you're using the cs50 IDE, it's a virtual machine(vm), running in parallel with many other processes on the physical hardware. Depending on how many other processes are running, your command spends time waiting rather than running. If another process is using any resource (such as the disks), yours has to wait for a turn.
In order to do the lab, you need to run all the combinations, consider the run times, and infer information. If you're seeing a small difference between runs, it shouldn't matter. If there are lots of other process (probably other vm's) running, it might skew the results a little. Concentrate on the "user" time, rather than the real time. The real time will be the most affected by other processes. The user time should only count when your process is getting it's turn.

1
  • This is also true outside of a VM. Algorithms will have variance in the amount of time they take to process, which is why time complexity is calculated using only the number of times that a given set of instructions will be executed and not how long they take to perform. Different cores of a CPU will run at different clock speeds and different processes will be "competing" for priority at runtime and these factors, among others, will play a part in the actual/real time an algorithm takes to run. – Robert S. Pratt Mar 19 at 10:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .