Categories:
.NET (357)
C (330)
C++ (183)
CSS (84)
DBA (2)
General (7)
HTML (4)
Java (574)
JavaScript (106)
JSP (66)
Oracle (114)
Perl (46)
Perl (1)
PHP (1)
PL/SQL (1)
RSS (51)
Software QA (13)
SQL Server (1)
Windows (1)
XHTML (173)
Other Resources:
Are pointers really faster than arrays?
Are pointers really faster than arrays? How much do function calls slow things down? Is ++i faster than i = i + 1?
✍: Guest
Precise answers to these and many similar questions depend of course on the processor and compiler in use. If you simply must know, you'll have to time test programs carefully. (Often the differences are so slight that hundreds of thousands of iterations are required even to see them.
For conventional machines, it is usually faster to march through large arrays with pointers rather than array subscripts, but for some processors the reverse is true. (Better compilers should generate good code regardless of which notation you use, though it's arguably easier for a compiler to convert array indices to pointers than vice versa .)
Function calls, though obviously incrementally slower than in-line code, contribute so much to modularity and code clarity that there is rarely good reason to avoid them. (Actually, by reducing bulk, functions can improve performance.) Also, some compilers are able to expand small, critical-path functions in-line, either as an optimization or at the programmer's request.
Before rearranging expressions such as i = i + 1, remember that you are dealing with a compiler, not a keystroke-programmable calculator. Any decent compiler will generate identical code for ++i, i += 1, and i = i + 1. The reasons for using ++i or i += 1 over i = i + 1 have to do with style, not efficiency.
2015-02-09, 1303👍, 0💬
Popular Posts:
Why is there extra white space before or after tables? This is often caused by invalid HTML syntax. ...
Write down the equivalent pointer expression for referring the same element a[i][j][k][l]? a[i] == *...
How can I implement a variable field width with printf? That is, instead of something like %8d, I wa...
.NET INTERVIEW QUESTIONS - What is the difference between System exceptions and Application exceptio...
What Is the "@SuiteClasses" Annotation? "@SuiteClasses" is a class annotation defined in JUnit 4.4 i...