Exploring the Access to the Static Array Elements via Indices and via Pointers — the Introductory C++ Case Expanded
Exploring the Access to the Static Array Elements via Indices and via Pointers — the Introductory C++ Case Expanded
Author(s): Robert Logožar, Matija Mikac, Danijel RadoševićSubject(s): ICT Information and Communications Technologies
Published by: Fakultet organizacije i informatike, Sveučilište u Zagrebu
Keywords: static arrays; pointers; C/C++; accessing the array elements; benchmarks;
Summary/Abstract: We revisit the old but formally still unresolved debate on the time efficiency of accessing the elements of 1D arrays via indices versus accessing them via pointers. To analyze that, we have programmed benchmarks of minimal complexity in the C++ language and inspected the machine code of their compilation in the x86 assembly language. Before exploring the performance, we briefly compared a few methods used for the execution time measurements. The results on the Wintel platform show no significant advantage in using pointers over indices except for some benchmarks and array (data) types. In other cases, the exact opposite may be true. The cause of this inconsistency lies in the compilation of the source code into the rather nonorthogonal x86 instruction set. Furthermore, the execution speed does not clearly relate to the instruction length. The parallel aim of this work is to provide a ground for further analysis and measurements of this kind using different compilers, languages, and computer platforms.
Journal: Journal of Information and Organizational Sciences
- Issue Year: 48/2024
- Issue No: 1
- Page Range: 49-80
- Page Count: 32
- Language: English