Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int i;
- int a[20];
- // Init all values to zero
- memset(a, 0, sizeof(a));
- for (i = 0; i < 20; i++) {
- printf("Value of %d is %dn", i, a[i]);
- }
- int i;
- int a[20];
- int * b;
- memset(a, 0, sizeof(a));
- b = a;
- for (i = 0; i < 20; i++) {
- printf("Value of %d is %dn", i, *b);
- b++;
- }
- _main:
- pushl %ebp
- movl %esp, %ebp
- pushl %edi
- pushl %esi
- pushl %ebx
- subl $108, %esp
- call ___i686.get_pc_thunk.bx
- "L00000000001$pb":
- leal -104(%ebp), %eax
- movl $80, 8(%esp)
- movl $0, 4(%esp)
- movl %eax, (%esp)
- call L_memset$stub
- xorl %esi, %esi
- leal LC0-"L00000000001$pb"(%ebx), %edi
- L2:
- movl -104(%ebp,%esi,4), %eax
- movl %eax, 8(%esp)
- movl %esi, 4(%esp)
- movl %edi, (%esp)
- call L_printf$stub
- addl $1, %esi
- cmpl $20, %esi
- jne L2
- addl $108, %esp
- popl %ebx
- popl %esi
- popl %edi
- popl %ebp
- ret
- _main:
- pushl %ebp
- movl %esp, %ebp
- pushl %edi
- pushl %esi
- pushl %ebx
- subl $124, %esp
- call ___i686.get_pc_thunk.bx
- "L00000000001$pb":
- leal -104(%ebp), %eax
- movl %eax, -108(%ebp)
- movl $80, 8(%esp)
- movl $0, 4(%esp)
- movl %eax, (%esp)
- call L_memset$stub
- xorl %esi, %esi
- leal LC0-"L00000000001$pb"(%ebx), %edi
- L2:
- movl -108(%ebp), %edx
- movl (%edx,%esi,4), %eax
- movl %eax, 8(%esp)
- movl %esi, 4(%esp)
- movl %edi, (%esp)
- call L_printf$stub
- addl $1, %esi
- cmpl $20, %esi
- jne L2
- addl $124, %esp
- popl %ebx
- popl %esi
- popl %edi
- popl %ebp
- ret
- movl -104(%ebp,%esi,4), %eax
- movl -108(%ebp), %edx
- movl (%edx,%esi,4), %eax
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- #include <iostream>
- using namespace std;
- typedef int64_t int64;
- static int64 nsTime() {
- struct timespec tp;
- clock_gettime(CLOCK_REALTIME, &tp);
- return tp.tv_sec*(int64)1000000000 + tp.tv_nsec;
- }
- typedef int T;
- size_t const N = 1024*1024*128;
- T data[N];
- int main(int, char**) {
- cout << "startingn";
- {
- int64 const a = nsTime();
- int sum = 0;
- for (size_t i=0; i<N; i++) {
- sum += data[i];
- }
- int64 const b = nsTime();
- cout << "Simple loop (indexed): " << (b-a)/1e9 << "n";
- }
- {
- int64 const a = nsTime();
- int sum = 0;
- T *d = data;
- for (size_t i=0; i<N; i++) {
- sum += *d++;
- }
- int64 const b = nsTime();
- cout << "Simple loop (pointer): " << (b-a)/1e9 << "n";
- }
- {
- int64 const a = nsTime();
- int sum = 0;
- for (size_t i=0; i<N; i++) {
- int a = sum+3;
- int b = 4-sum;
- int c = sum+5;
- sum += data[i] + a - b + c;
- }
- int64 const b = nsTime();
- cout << "Loop that uses more ALUs (indexed): " << (b-a)/1e9 << "n";
- }
- {
- int64 const a = nsTime();
- int sum = 0;
- T *d = data;
- for (size_t i=0; i<N; i++) {
- int a = sum+3;
- int b = 4-sum;
- int c = sum+5;
- sum += *d++ + a - b + c;
- }
- int64 const b = nsTime();
- cout << "Loop that uses more ALUs (pointer): " << (b-a)/1e9 << "n";
- }
- }
- char p1[ ] = "12345";
- char* p2 = "12345";
- char *ch = p1[ 3 ]; /* 4 */
- ch = *(p2 + 3); /* 4 */
- char p1[ ] = "12345";
- char* p2 = "12345";
- char *ch = p1[ 3 ]; /* 4 */
- ch = *(p2 + 3); /* 4 */
Add Comment
Please, Sign In to add comment