Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdint.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- void main(){
- int16_t *arr, *lookup;
- long long int sum = 0, value = 0, count = 0, size = 500000000;
- arr = (int16_t*) calloc(size, sizeof(int16_t));
- lookup = (int16_t*) calloc(65535, sizeof(int16_t));
- srand(1);
- for(count = 0; count < size; count++){
- arr[count] = (rand() % 65537) - 32769;
- }
- for(count = 0; count < 65536; count++){
- value = count;
- lookup[count] = (value - 32768) * 0.75;
- }
- clock_t begin = clock();
- for(count = 0; count < size; count++){
- value = arr[count];
- arr[count] = lookup[value + 32768];
- }
- clock_t end = clock();
- double time_spent = (double)(end - begin) / CLOCKS_PER_SEC;
- for(count = 0; count < size; count++){
- sum += arr[count];
- }
- printf("sum is %d\n", sum);
- printf("time taken for part b was %lf\n", time_spent);
- free(arr);
- free(lookup);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement