-
-
Save est31/f364e26883439e8968a1 to your computer and use it in GitHub Desktop.
benchmark
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
#!/bin/sh | |
gcc -c -fpic lib.c | |
gcc -shared -o libfoo.so lib.o | |
gcc -L`pwd` -O3 -o test test.c -lfoo | |
echo "Before calling ./test, please do export LD_LIBRARY_PATH=`pwd`:\$LD_LIBRARY_PATH" |
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
#include "lib.h" | |
void do_something(float i) { /* lol, nothing XD */ } |
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
void do_something(float i); |
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
#include <stdio.h> | |
#include <time.h> | |
#include <stdint.h> | |
#include "lib.h" | |
int main() { | |
clock_t t1, t2, t3, t4, t5, t6; | |
clock_t e; | |
t1 = clock(); | |
uint64_t i; | |
uint64_t num_it = 1000 * 1000 * 10; | |
float inv1000 = 1/1000.0; | |
float inv1024 = 1/1024.0; | |
float t = 157963; | |
for (i = 0; i < num_it; i++) { | |
do_something(i * inv1000); | |
} | |
t2 = clock(); | |
for (i = 0; i < num_it; i++) { | |
do_something(i / 1000.0); | |
} | |
t3 = clock(); | |
for (i = 0; i < num_it; i++) { | |
do_something(i * inv1024); | |
} | |
t4 = clock(); | |
for (i = 0; i < num_it; i++) { | |
do_something(i / 1024.0); | |
} | |
t5 = clock(); | |
for (i = 0; i < num_it; i++) { | |
do_something(i); | |
} | |
t6 = clock(); | |
e = t6 - t5; | |
printf("Not accounting for overhead: %f\n", (float)e / CLOCKS_PER_SEC); | |
printf("%f %f %f %f\n", | |
(float)(t2 - t1 - e) / CLOCKS_PER_SEC, (float)(t3 - t2 - e) / CLOCKS_PER_SEC, | |
(float)(t4 - t3 - e) / CLOCKS_PER_SEC, (float)(t5 - t4 - e) / CLOCKS_PER_SEC); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment