-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbenchmark.c
More file actions
47 lines (38 loc) · 1.15 KB
/
benchmark.c
File metadata and controls
47 lines (38 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include"min.h"
#include<stdio.h>
#include<stdlib.h>
#include<x86intrin.h>
volatile int scratch=0;
#define MAX 1024*1024
int array[MAX] __attribute__((aligned(64)));
int main(int argc, char** argv) {
int seed=789;
for(int i=0;i<MAX;i++,seed+=789) {
array[i]=seed%MAX+12;
}
unsigned dummy = 0;
long long before, after;
for(int size=8;size<=MAX;size*=2) {
before = __rdtscp(&dummy);
for(int i=0;i<1000;i++) {
scratch=arraymin(array,size);
}
after = __rdtscp(&dummy);
printf("Arraymin %d took %lld cycles/op %.2f cycles/element.\n",size,(after-before)/1000,(after-before)/(1000.0*size));
}
// int size=64;
// before = __rdtscp(&dummy);
// for(int i=0;i<1000;i++) {
// scratch=arraymin64(array);
// }
// after = __rdtscp(&dummy);
// printf("Arraymin64 %d took %lld cycles/op %.2f cycles/element.\n",size,(after-before)/1000,(after-before)/(1000.0*64));
for(int size=8;size<=MAX;size*=2) {
before = __rdtscp(&dummy);
for(int i=0;i<1000;i++) {
scratch=minindex(array,size);
}
after = __rdtscp(&dummy);
printf("Minindex %d took %lld cycles/op %.2f cycles/element.\n",size,(after-before)/1000,(after-before)/(1000.0*size));
}
}