Skip to content

Instantly share code, notes, and snippets.

@est31

est31/compile.sh Secret

Last active August 29, 2015 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save est31/f364e26883439e8968a1 to your computer and use it in GitHub Desktop.
Save est31/f364e26883439e8968a1 to your computer and use it in GitHub Desktop.
benchmark
#!/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"
#include "lib.h"
void do_something(float i) { /* lol, nothing XD */ }
void do_something(float i);
#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