CKTIS / C
performance and complexity — concept C23
Performance depends on algorithmic complexity, memory locality, allocation count, and target; preserve correctness first, then measure a representative workload. A micro-optimization based on undefined behavior is a bug.
Version: C23
Syntax
performance and complexityPerformance depends on algorithmic complexity, memory locality, allocation count, and target; preserve correctness first, then measure a representative workload. A micro-optimization based on undefined behavior is a bug.
First choose the right algorithm and data layout, then measure time and allocations on representative input in a production-style build. A contiguous array often improves locality over a pointer list, while batching reduces I/O calls.
Account for cache warm-up, measurement variance, optimization removing an unused result, and worst-case data. Do not turn volatile into a benchmarking tool for ordinary memory, and do not assume a result from one architecture transfers to another.
Examples
#include <stdio.h>
int main(void) { int values[] = {1, 2, 3, 4}; int sum = 0; for (size_t i = 0; i < 4; ++i) sum += values[i]; printf("%d\n", sum); return 0; }
Result
10
Performance depends on algorithmic complexity, memory locality, allocation count, and target; preserve correctness first, then measure a representative workload. A micro-optimization based on undefined behavior is a bug.