Quote:
Originally Posted by
redoubtable
Despite what everyone said I think speed differences between both cases are not mensurable.
It IS measurable. But even after 1/2 million invocations, it made almost no difference on a very slow (10-year old) machine.
Quote:
For one, memory is stored in the data segment in both cases thus it's accessed in the same way/speed.
mostly wrong. The '@' literal is embedded in the machine instructions itself (for x86 architectures), so that's in the code segment. The "const" designation for a variable means the compiler can optimize that variable, for instance, by also "hard coding" the value inside instructions. However, I did not turn on optimizations. In my code, I defined the const char to be inside the main() call, meaning it would go on the stack. Do nothing is on the data segment. Finally, the call to strchr places both arguments on the stack. So the price of having a constant in an immediate instruction type is practically nullified by this.
Quote:
Furthermore, this is highly platform/architecture/implementation dependent.
Architecture and processor, yes. For instance, while practically all processors have both an 'immediate' addressing and a 'direct' addressing mode, the difference in the number of clock cycles to process such an argument varies across architectures (surely), processor manufacturers (AMD vs Intel), and processor families (Pentium vs Celeron). There almost always IS a difference, but in very-large-pipelined architectures and efficient caching, that difference is statistically erased.
However, there's more dependency on the compiler. Whether the compiler chooses immediate mode or direct mode for literals, whether it uses direct or stack-indexed addressing addressing for constants, weather it passes the first argument in using a register or the last, etc, etc. The OS can come into play, too, especially with my program of 100000 lines of code. This likely meant there were page-traps during the execution. For this reason (and others), I took an average of several runs.
Quote:
We should call a meta-programmer to enlighten us with accurate specifications on the matter at hand.
WTF do you mean by a
metaprogrammer??