Group Members: Tan, Timothy Joshua O. & Recato Dy, John Kieffer L.
Input: Scalar variable n (integer) contains the length of the vector; Vectors X and Y are both single precision float.
Process: Y[i] = X[i-3] + X[1-2] + X[i-1] + X[i] + X[i+1] + X[i+2] + X[i+3]
Example: X -> 1,2,3,4,5,6,7,8; output Y -> 28, 35
Output: Store result in vector Y. Display the result of the first ten elements of vector Y for all versions of kernel (i.e. C and x86-64).
In this project, we compared the execution times of a C program and its equivalent Assembly implementation in both Debug and Release modes using Visual Studio. The purpose was to analyze the performance differences between the two programming languages and the impact of compiler optimizations. The execution times below were obtained by running each kernel implementation 30 times and then averaging the results.
In Debug mode, the Assembly kernel version of the code consistently outperformed the C version by a significant margin. On average, the Assembly code ran approximately three times faster than the C code across different input sizes (220, 224, and 230).
The primary reason for this performance difference is that in Debug mode, C has debug features enabled and optimization features disabled. Debug features, such as the inclusion of debugging symbols and the absence of code optimizations, can introduce additional overhead and slow down the execution of the C code.
In contrast, Assembly code is a low-level programming language that provides direct control over the processor's instructions. Even in Debug mode, the Assembly code is already optimized since it is written at a lower level and does not include the same debug features as C. This allows the Assembly code to execute more efficiently, resulting in faster execution times.
Debug Mode | 220 | 224 | 230 |
---|---|---|---|
C Average Time | 4.57ms | 74.83ms | 5354.27ms |
Assembly Average Time | 1.47ms | 22.90ms | 1707.53ms |
Assembly Code Speed (vs. C) | 311.36% | 326.78% | 313.57% |
In Release mode, the performance comparison yielded different results. The C version of the code outperformed the Assembly version by approximately 20% across all input sizes.
This can be attributed to the fact that in Release mode, C has its debug features disabled and optimization features enabled. The C compiler applies various optimization techniques, such as code reordering, constant folding, and loop unrolling, to improve the performance of the generated machine code.
On the other hand, the Assembly code, while still optimized, may not benefit from the same level of optimization as the C code. The C compiler has access to a wider range of optimization techniques and can make more informed decisions based on the program's structure and data flow analysis.
In addition, the performance of Assembly code can vary depending on the specific implementation and the programmer's expertise in writing optimized Assembly instructions. In this case, the Assembly code implementation may not have been as efficiently optimized as the C code generated by the compiler in Release mode.
Release Mode | 220 | 224 | 230 |
---|---|---|---|
C Average Time | 1.07ms | 17.10ms | 1290.53ms |
Assembly Average Time | 1.33ms | 23.00ms | 1527.83ms |
Assembly Code Speed (vs. C) | 80.00% | 74.35% | 84.47% |