109 - Vector Length and Performance (Short Vector)
$ cd tutorial/109
$ cat -n vlen.c // Assign 1D vector to 2D array in myloop()
Assign very short (N=16 entry) 1D vectors into (N=16 entry) * (M=4M entry) 2D array.
code:vlen.c
13 double aM * (N+1); /* 2 dim array, 64M + pad */ 16 void myloop(int m, int n) {
17 int i, j;
18 for(i = 0; i < n; i++) {
19 for(j = 0; j < m; j++) {
21 }
22 }
23 }
24
27 myloop(M, N);
---
$ gcc -O vlen.c
$ a.out // 0.507 sec
$ ncc -ftrace vlen.c -o n.out
$ n.out // 0.062 sec = 8.18 times speed against gcc.
https://gyazo.com/578c1340d41007b928ed3162f92360a8
$ ls
$ ftrace -f ftrace.out // average vector len in 'myloop' is 16, which prevent speed-up.
https://gyazo.com/3432376db391bba22575e83ac00cc780