Created
July 20, 2010 20:30
-
-
Save ice799/483524 to your computer and use it in GitHub Desktop.
ugly testing harness
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rm *.o test | |
as -a --gstabs --64 -march=core2 -o funcs64.o funcs64.S | |
gcc test.c -Wall -m64 -march=core2 -c | |
gcc funcs64.o test.o -Wall -m64 -march=core2 -o test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.text | |
.align 8 | |
.globl test1 | |
.type test1,@function | |
.globl test2 | |
.type test2,@function | |
test1: | |
pushq %rbp | |
movq %rsp,%rbp | |
leave | |
ret | |
test2: | |
sub $0x8, %rsp | |
movq %rbp, (%rsp) | |
movq (%rsp), %rbp | |
add $0x8, %rsp | |
ret |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for i in {1..2500} | |
do | |
./test >> results.txt | |
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define _GNU_SOURCE | |
#include <errno.h> | |
#include <sched.h> | |
#include <stdint.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <unistd.h> | |
#include <sys/time.h> | |
#define TEST_RUNS 500000000 | |
extern void | |
test1(); | |
extern void | |
test2(); | |
static __inline__ unsigned long long | |
rdtsc(void) | |
{ | |
unsigned long hi = 0, lo = 0; | |
__asm__ __volatile__ ("lfence\n\trdtsc" : "=a"(lo), "=d"(hi)); | |
return ( (unsigned long long)lo)|( ((unsigned long long)hi)<<32 ); | |
} | |
static void | |
run_test(void (*fn)(void), const char *id) | |
{ | |
size_t i = 0; | |
long long before_cycles = 0, after_cycles = 0; | |
struct timeval before_tv, after_tv; | |
memset(&before_tv, 0, sizeof before_tv); | |
memset(&after_tv, 0, sizeof after_tv); | |
gettimeofday(&before_tv, NULL); | |
before_cycles = rdtsc(); | |
for (; i < TEST_RUNS; i++) { | |
fn(); | |
} | |
after_cycles = rdtsc(); | |
gettimeofday(&after_tv, NULL); | |
printf("Result %s: %lld cycles\n", id, after_cycles - before_cycles); | |
printf("Result %s: %ld microsecs\n", | |
id, | |
((after_tv.tv_sec - before_tv.tv_sec) * 1000000) + | |
(after_tv.tv_usec - before_tv.tv_usec)); | |
} | |
int | |
main(int argc, char *argv[]) | |
{ | |
int ret = 0; | |
cpu_set_t mask; | |
CPU_ZERO(&mask); | |
CPU_SET((int)3, &mask); | |
ret = sched_setaffinity(0, sizeof mask, &mask); | |
if (ret == -1) { | |
perror("setting cpu affinity failed"); | |
exit(EXIT_FAILURE); | |
} | |
sleep(2); | |
run_test(test1, "test1 (frame pointer)"); | |
run_test(test2, "test2 (no frame pointer)"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment