Created
January 4, 2018 05:51
-
-
Save begeekmyfriend/08f004b201c01db1e8914ffd91d4c00d to your computer and use it in GitHub Desktop.
Persudo random generator according to benchmark
This file contains hidden or 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 <stdlib.h> | |
#include <time.h> | |
#include <unistd.h> | |
int main(void) | |
{ | |
int i, j, k; | |
int dim = 11; | |
int num = 1024 * 1024; | |
int loop = 1000; | |
struct timespec start, end; | |
size_t stat[200] = { 0 }; | |
for (k = 0; k < loop; k++) { | |
usleep(50000); | |
srandom(time(NULL)); | |
clock_gettime(CLOCK_MONOTONIC, &start); | |
for (i = 0; i < num; i++) { | |
double *vector = malloc(dim * sizeof(double)); | |
for (j = 0; j < dim; j++) { | |
vector[j] = (double) random() / RAND_MAX * 20 - 10; | |
} | |
free(vector); | |
} | |
clock_gettime(CLOCK_MONOTONIC, &end); | |
size_t rand_ms = (end.tv_sec - start.tv_sec)*1000 + (end.tv_nsec - start.tv_nsec)/1000000; | |
stat[rand_ms]++; | |
} | |
for (i = 0; i < sizeof(stat)/sizeof(*stat); i++) { | |
printf("[%d](%f\%):", i, 100.0 * stat[i] / loop); | |
for (j = 0; j < stat[i]; j++) { | |
putchar('-'); | |
} | |
putchar('\n'); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment