Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <inttypes.h>
- #include <stdint.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- #define NUM_SAMPLES 500000000
- int randomInt(int min, int max) {
- return rand() % max + min;
- }
- int main() {
- srand(42);
- printf("Starting.\n");
- // Create a large (500M?) array of int16_t numbers to represent sound samples.
- int16_t* samples = calloc(NUM_SAMPLES, 2);
- for (int i = 0; i < NUM_SAMPLES; i++) {
- samples[i] = randomInt(INT16_MIN, INT16_MAX);
- }
- clock_t begin = clock();
- // TEST
- for (int i = 0; i < NUM_SAMPLES; i++) {
- samples[i] = samples[i] * 0.75;
- }
- // /TEST
- clock_t end = clock();
- // Anti-optimization
- int sum = 0;
- for (int i = 0; i < NUM_SAMPLES; i++) {
- sum += samples[i];
- }
- // /Anti-optimization
- double time_spent = (double)(end - begin) / CLOCKS_PER_SEC;
- printf("Sum: %d, Time spent: %.3f\n", sum, time_spent);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement