Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <time.h>
- enum {
- MAX_HWM = 0x800000,
- };
- int computeNewHighWaterMark(unsigned int n) {
- if (n >= MAX_HWM) {
- n = MAX_HWM;
- } else {
- n--;
- n |= n >> 1;
- n |= n >> 2;
- n |= n >> 4;
- n |= n >> 8;
- n |= n >> 16;
- n++;
- }
- return n;
- }
- int* getResults(void) {
- int* results = malloc(sizeof(*results) * 100);
- for (int i=0; i<100; i++) {
- results[i] = computeNewHighWaterMark((unsigned) i);
- }
- return results;
- }
- int main(void) {
- int** stored = malloc(sizeof(int*) * 100);
- struct timespec tstart={0,0}, tend={0,0};
- timespec_get(&tstart, TIME_UTC);
- for (int i=0; i<100; i++) {
- stored[i] = getResults();
- }
- timespec_get(&tend, TIME_UTC);
- long ns = tend.tv_nsec - tstart.tv_nsec;
- double ms = ((double) ns) / 1000000;
- printf("Time: %fms Raw ns: %ld\n\nResults:\n", ms, ns);
- // Print 1st entry from results
- int* entries = stored[0];
- for (int i=0; i<100; i++) {
- int entry = entries[i];
- printf("f(%d): %d\n", i, entry);
- }
- for (int i=0; i<100; i++) {
- free(stored[i]);
- }
- free(stored);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement