diff --git a/Makefile b/Makefile index 3fe0615..c922db4 100644 --- a/Makefile +++ b/Makefile @@ -3,10 +3,11 @@ # .SUFFIXES: .cpp .o .c .h ifeq ($(DEBUG),1) -CFLAGS = -fPIC -std=c99 -ggdb -march=native -Wall -Wextra -Wshadow -fsanitize=undefined -fno-omit-frame-pointer -fsanitize=address +CFLAGS = -fPIC -std=gnu99 -ggdb -march=native -Wall -Wextra -Wshadow -fsanitize=undefined -fno-omit-frame-pointer -fsanitize=address else -CFLAGS = -fPIC -std=c99 -O3 -march=native -Wall -Wextra -Wshadow +CFLAGS = -fPIC -std=gnu99 -O3 -march=native -Wall -Wextra -Wshadow endif # debug +LDLIBS=-lrt all: despacebenchmark HEADERS=./include/despacer.h ./include/despacer_tables.h diff --git a/benchmarks/despacebenchmark.c b/benchmarks/despacebenchmark.c index 510b8a3..607b3b9 100644 --- a/benchmarks/despacebenchmark.c +++ b/benchmarks/despacebenchmark.c @@ -5,6 +5,8 @@ #include <string.h> #include "despacer.h" +#include <time.h> + #define RDTSC_START(cycles) do { register unsigned cyc_high, cyc_low; @@ -35,6 +37,8 @@ fflush(NULL); uint64_t tm1, tm2; uint64_t min_diff = (uint64_t)-1; + struct timespec start_time, end_time; + clock_gettime(CLOCK_MONOTONIC, &start_time); for (int i = 0; i < repeat; i++) { pre; __asm volatile("" ::: /* pretend to clobber */ "memory"); @@ -45,7 +49,12 @@ if (tmus < min_diff) min_diff = tmus; } + clock_gettime(CLOCK_MONOTONIC, &end_time); + uint64_t start_ns = start_time.tv_sec * 1000000000 + start_time.tv_nsec; + uint64_t end_ns = end_time.tv_sec * 1000000000 + end_time.tv_nsec; + uint64_t nsecs = end_ns - start_ns; printf(" %f cycles / ops", min_diff * 1.0 / number); + printf(" %lu nsec (%f sec) ", nsecs, nsecs * 1e-9); printf("n"); fflush(NULL); } while (0) @@ -56,6 +65,8 @@ fflush(NULL); uint64_t tm1, tm2; uint64_t min_diff = (uint64_t)-1; + struct timespec start_time, end_time; + clock_gettime(CLOCK_MONOTONIC, &start_time); for (int i = 0; i < repeat; i++) { pre; __asm volatile("" ::: /* pretend to clobber */ "memory"); @@ -67,7 +78,12 @@ if (tmus < min_diff) min_diff = tmus; } + clock_gettime(CLOCK_MONOTONIC, &end_time); + uint64_t start_ns = start_time.tv_sec * 1000000000 + start_time.tv_nsec; + uint64_t end_ns = end_time.tv_sec * 1000000000 + end_time.tv_nsec; + uint64_t nsecs = end_ns - start_ns; printf(" %f cycles / ops", min_diff * 1.0 / number); + printf(" %lu nsec (%f sec) ", nsecs, nsecs * 1e-9); printf("n"); fflush(NULL); } while (0) @@ -96,7 +112,7 @@ size_t fillwithtext(char *buffer, size_t size) { } int main() { - const int N = 1024; + const int N = 1024; //*1024; char *buffer = malloc(N); char *tmpbuffer = malloc(N); int repeat = 100;
diff --git a/Makefile b/Makefile index 3fe0615..c922db4 100644 --- a/Makefile +++ b/Makefile @@ -3,10 +3,11 @@ # .SUFFIXES: .cpp .o .c .h ifeq ($(DEBUG),1) -CFLAGS = -fPIC -std=c99 -ggdb -march=native -Wall -Wextra -Wshadow -fsanitize=undefined -fno-omit-frame-pointer -fsanitize=address +CFLAGS = -fPIC -std=gnu99 -ggdb -march=native -Wall -Wextra -Wshadow -fsanitize=undefined -fno-omit-frame-pointer -fsanitize=address else -CFLAGS = -fPIC -std=c99 -O3 -march=native -Wall -Wextra -Wshadow +CFLAGS = -fPIC -std=gnu99 -O3 -march=native -Wall -Wextra -Wshadow endif # debug +LDLIBS=-lrt all: despacebenchmark HEADERS=./include/despacer.h ./include/despacer_tables.h diff --git a/benchmarks/despacebenchmark.c b/benchmarks/despacebenchmark.c index 510b8a3..607b3b9 100644 --- a/benchmarks/despacebenchmark.c +++ b/benchmarks/despacebenchmark.c @@ -5,6 +5,8 @@ #include <string.h> #include "despacer.h" +#include <time.h> + #define RDTSC_START(cycles) do { register unsigned cyc_high, cyc_low; @@ -35,6 +37,8 @@ fflush(NULL); uint64_t tm1, tm2; uint64_t min_diff = (uint64_t)-1; + struct timespec start_time, end_time; + clock_gettime(CLOCK_MONOTONIC, &start_time); for (int i = 0; i < repeat; i++) { pre; __asm volatile("" ::: /* pretend to clobber */ "memory"); @@ -45,7 +49,12 @@ if (tmus < min_diff) min_diff = tmus; } + clock_gettime(CLOCK_MONOTONIC, &end_time); + uint64_t start_ns = start_time.tv_sec * 1000000000 + start_time.tv_nsec; + uint64_t end_ns = end_time.tv_sec * 1000000000 + end_time.tv_nsec; + uint64_t nsecs = end_ns - start_ns; printf(" %f cycles / ops", min_diff * 1.0 / number); + printf(" %lu nsec (%f sec) ", nsecs, nsecs * 1e-9); printf("n"); fflush(NULL); } while (0) @@ -56,6 +65,8 @@ fflush(NULL); uint64_t tm1, tm2; uint64_t min_diff = (uint64_t)-1; + struct timespec start_time, end_time; + clock_gettime(CLOCK_MONOTONIC, &start_time); for (int i = 0; i < repeat; i++) { pre; __asm volatile("" ::: /* pretend to clobber */ "memory"); @@ -67,7 +78,12 @@ if (tmus < min_diff) min_diff = tmus; } + clock_gettime(CLOCK_MONOTONIC, &end_time); + uint64_t start_ns = start_time.tv_sec * 1000000000 + start_time.tv_nsec; + uint64_t end_ns = end_time.tv_sec * 1000000000 + end_time.tv_nsec; + uint64_t nsecs = end_ns - start_ns; printf(" %f cycles / ops", min_diff * 1.0 / number); + printf(" %lu nsec (%f sec) ", nsecs, nsecs * 1e-9); printf("n"); fflush(NULL); } while (0) @@ -96,7 +112,7 @@ size_t fillwithtext(char *buffer, size_t size) { } int main() { - const int N = 1024; + const int N = 1024; //*1024; char *buffer = malloc(N); char *tmpbuffer = malloc(N); int repeat = 100;
|