#include #include #include void measure_stack_allocation(volatile int size) { volatile int array[size]; } void measure_heap_allocation(volatile int size) { volatile int *array = (volatile int *)malloc(size * sizeof(volatile int)); free((void *)array); } int main(int argc, char *argv[]) { if (argc != 2) { fprintf(stderr, "Usage: %s \n", argv[0]); return 1; } int size = atoi(argv[1]); if (size <= 0) { fprintf(stderr, "Array size must be a positive integer\n"); return 1; } int iterations = 10000; clock_t start, end; double cpu_time_used; start = clock(); for (int i = 0; i < iterations; i++) { measure_stack_allocation(size); } end = clock(); cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC; printf("Stack allocation time: %f seconds\n", cpu_time_used); start = clock(); for (int i = 0; i < iterations; i++) { measure_heap_allocation(size); } end = clock(); cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC; printf("Heap allocation time: %f seconds\n", cpu_time_used); return 0; }