Estimating the average amount of time that passes when we we read elements element in a loop/iteration I was trying to estimate the amount of time that pass by a program when we read one element from its array (say in python).
Say that I have the times $t_i$ when I traversed a number of elements in the following program:
array = [...]
t_i_array = []
while i < n:
  t_start = time.start()
  n_i = random.randint()
  a.readKelements(n_i)
  t_end = time.start()
  t_i = t_end - t_start
  t_i_array.append(t_i)
  i++

What is the correct estimate for the average time that passes when we read 1 element? (i.e. time per element, instead of elements per unit time)
Is it:
$$\mu = \frac{\sum^{n}_{i=1} t_i}{\sum^{n}_{i=1} n_i}$$
or is it:
$$\mu = \sum^{n}_{i=1} \frac{t_i}{n_i}$$
Note that $t_i$ is the time to read $n_i$ elements on iteration i.
If they do not estimate the quantity I want, then what is the difference between them?
Why is the following reasoning flawed?
$\frac{t_i}{n_i}$ is the average time to traverse 1 element. Then, why don't we don't this a bunch of times and average those results (what my second equation is doing). Why is that wrong? If you can address that issue at an intuitive level and if possible, at a mathematically rigorous level, that would be optimal.
 A: The usual "average time per element" is total elements on total time.
$\hat\mu = \frac{\sum^{n}_{i=1} t_i}{\sum^{n}_{i=1} n_i}$
The other formula is actually a sum of averages, and doesn't estimate what you want. Consider the case where all the $n_i$ are 1 and compare the two formulas - the first formula gives $∑t_i/n$ (a simple average of individual times) while the second gives $∑t_i$, the total time, exactly $n$ times too large. Now consider a case where the $n_i$ are all 2, the result is again $n$ times too large. 
You say in your edit that your second formula is averaging the $t_i/n_i$ ... but it isn't. It merely sums them.
A modified version of the second formula - one where we divide by $n$, would average them:
$\hat\mu = \frac{_1}{^n} \sum^{n}_{i=1} \frac{t_i}{n_i}$
- and in that case, would also be an estimate of the average but with different weighting to the ordinary average.

If the variance of $t_i$ is proportional to $n_i^\alpha$, then the variance of $t_i/n_i$ is $\propto n_i^{\alpha-2}$, and an appropriate* weighted average $\frac{\sum^{n}_{i=1} w_i (t_i/n_i)}{\sum^{n}_{i=1} w_i}$ uses $w_i\propto 1/n_i^{\alpha-2}$.
* optimal in the sense of being minimum variance
When $\alpha=2$ that gives the second formula, and when $\alpha=1$ it gives the first formula.
That is, either formula might apply perfectly (or neither of them, at least not perfectly) depending on the situation. Using the "wrong" weighting will still estimate the right thing as long as the $t_i/n_i$ share the same population mean, but less efficiently (possibly, in some cases, much less efficiently).
So the question then becomes, how is the variance of $t_i$ related to $n_i$? Does it increase linearly in $n_i$, or as the square?
