Edit: Since this post is gaining traction, I feel the need to clarify that the purpose of this is to see if asymptotic and constant factor estimations calculated from high level code implementations of algorithms are reasonable approximations of the true version. I am not trying to predict the speed of code when running.
Suppose I have some sequence of code $C$ in a high level language (C++, Python, Java, etc.) which needs to be converted into machine code which we will call $M$. Obviously machine code varies from system to system, so assume we are on a fixed machine
Under a uniform cost model, we can say that every instruction of $M$ costs $1$ operation, so we can calculate the complexity of our code as some function of the input size of our problem $n$. Let an upper bound of this function be $f_M(n)$.
Clearly, nobody writes in machine code, so we can approximate $f_M(n)$ by counting operations of our high level language code $C$, which we can say $f_C(n)$
Define $1$ operation of $C$ to be the following
1. Function Calls
2. Returning
3. Arithmetic Operators
4. Logical Operators
5. Comparisons
6. Pointer/Object dereferencing/Array indexing
7. Variable Assignment
This list is heuristic, and was given to me as a means of approximating by an engineer mentor, so if a better heuristic exists please let me know.
Questions: Given $f_C(n)$, are we guaranteed any of the following, assuming the code is compiled in "good faith" (no additional logic added to insert unnecessary operations)
- Does $f_C(n)\in \mathcal{O}(g(n))$ imply $f_M(n)\in \mathcal{O}(g(n))$?
- Does there exist a constant factor such that $f_M(n)\leq c\cdot f_C(n)$? for sufficiently large $n$?