Last active
May 2, 2017 14:48
-
-
Save xk/b8b2ff4ab1455237906a8b13e3f1f02f to your computer and use it in GitHub Desktop.
Another useless benchmark to illustrate a point
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
// 2017-04-30 jorge@jorgechamorro.com | |
// See http://www.eevblog.com/forum/projects/in-search-of-a-supercomputer | |
#include <pthread.h> | |
#include <stdlib.h> | |
#define BUF_SIZE 16*1024*1024 | |
pthread_t t1, t2, t3, t4; | |
double* nu_buffer () { return (double*) malloc(BUF_SIZE); } | |
void* thread_proc (void* arg) { | |
int i= BUF_SIZE/8; | |
double* buffer= nu_buffer(); | |
while (i--) buffer[i]= (((double*) arg)[i] + buffer[i]) / 2.0; | |
return buffer; | |
} | |
void do_threads_stuff (double* buffer) { | |
pthread_create(&t1, NULL, thread_proc, buffer); | |
pthread_create(&t2, NULL, thread_proc, buffer); | |
pthread_create(&t3, NULL, thread_proc, buffer); | |
pthread_create(&t4, NULL, thread_proc, buffer); | |
void* r; | |
pthread_join(t1, &r), free(r); | |
pthread_join(t2, &r), free(r); | |
pthread_join(t3, &r), free(r); | |
pthread_join(t4, &r), free(r); | |
} | |
int main (void) { | |
double* buffer= nu_buffer(); | |
do_threads_stuff(buffer); | |
//free(buffer); return 0; | |
} | |
/* | |
The i7 Mac: | |
unibodySierra:Desktop admin$ gcc -O0 threads.c -o threads | |
unibodySierra:Desktop admin$ time ./threads | |
real 0m0.054s | |
user 0m0.084s | |
sys 0m0.073s | |
And the OPi Zero: | |
pi@orangepi:~$ gcc -lpthread -O0 threads.c -o threads | |
pi@orangepi:~$ time ./threads | |
real 0m0.166s | |
user 0m0.440s | |
sys 0m0.140s | |
And the Mac is 0,166/0,054= only 3x times faster. | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment