Skip to main content

Code Measurement

How to Measure Performance of Your Code

Measuring code performance accurately is crucial, especially when optimizing the existing algorithms or designing new ones. In this post, I’ll share my learnings of measuring code performance using various tools and techniques. For measuring execution time, we can use the following techniques: Wall Clock Time (clock_gettime) Linux resource usage metrics (getrusage) To measure raw Time Stamp Counter (or, ticks), on x86 architectures we can use: RDTSC (Read Time-Stamp Counter) Finally, to pinpoint performance bottlenecks, we can use the Linux perf tool; However, there are two ways to use it: