Note that any answer to this question is going to be dependant on what exactly the system is doing at any given time. For example:
- What kernel scheduler you're using (their latencies differ)
- What processes are you're running (they all compete for time, and the scheduler may not choose you're processes as early as you'd like)
And probably a thousand other things. For this reason, run this test yourself. Also note that the following could be wrong in many subtle ways, since I'm not very knowledgable about getting the best performance possible out of bash
(well, zsh
strictly speaking, since that's my login shell).
With this in mind, I devised a simple way to test this. GNU date has a way to show nanoseconds (yes, you read that correctly). Thus, to get a bunch of data, all you need to do is:
get_starting_diff() {
date +%N & date +%N
}
# 5,000 iterations is probably good enough statistically
for iteration in $(seq 1 5000); do
get_starting_diff
done > times
This will (besides chewing up a lot of PIDs) produce 10,000 line file, with the timing information in it. You can then use the following Python (v3.4) script to get an idea of what you're average timing difference is:
def pairwise(iterator):
"Takes an iterator and extracts sequential pairs from it"
pair = []
for item in iterator:
pair.append(item)
if len(pair) == 2:
yield pair
pair = []
diffs = []
with open('times') as data:
for start1, start2 in pairwise(data):
diffs.append(int(start2) - int(start1))
diffs.sort()
median = diffs[len(diffs) // 2]
mean = sum(diffs) / len(diffs)
print("The median difference is", median / 1000000, "milliseconds")
print("The mean difference is", mean / 1000000, "milliseconds")
On my (Ubuntu 13.10, Linux 3.12.0-997-generic) system, this gives me:
The median difference is 1.077483 milliseconds
The mean difference is 3.680928442211055 milliseconds