# Counting cycles - RDTSC

DevFeed: [Counting cycles - RDTSC](<https://devfeed.tech/articles/counting-cycles-rdtsc-38920.md>)

Original publisher: [Read original article](<https://idea.popcount.org/2013-01-28-counting-cycles---rdtsc>)

Author: Marek

Published: 2013-01-27T23:00:00Z

Content type: tutorial

Language: en

Sources: [Marek Majkowski](<https://devfeed.tech/sources/marek-majkowski.md>)

Topics: [benchmarking](<https://devfeed.tech/topics/benchmarking.md>), [cpu](<https://devfeed.tech/topics/cpu.md>), [Benchmark](<https://devfeed.tech/topics/benchmark.md>), [Code](<https://devfeed.tech/topics/code.md>), [Cache](<https://devfeed.tech/topics/cache.md>), [Kernel](<https://devfeed.tech/topics/kernel.md>), [execution](<https://devfeed.tech/topics/execution.md>)

Tags: [benchmark](<https://devfeed.tech/tags/benchmark.md>), [benchmarking](<https://devfeed.tech/tags/benchmarking.md>), [cache](<https://devfeed.tech/tags/cache.md>), [code](<https://devfeed.tech/tags/code.md>), [cpu](<https://devfeed.tech/tags/cpu.md>), [kernel](<https://devfeed.tech/tags/kernel.md>), [measurements](<https://devfeed.tech/tags/measurements.md>)

## AI overview

This article explains how to measure CPU cycles with RDTSC when benchmarking code. It recommends reducing hardware and system sources of variability, warming the instruction cache, and accounting for the fixed cost of timing code.

## Source excerpt

Counting cycles - RDTSC In 2010 Intel engineer, Gabriele Paoloni, released a very informative paper on How To Benchmark Code Execution. It boils down to the following observations regarding counting CPU cycles: - Disable hyper-threading, frequency scaling and turbo mode. Ie: all hardware sources of indeterminism. - Consider loading your code to a kernel module for a benchmark. - Disable interrupts. - Use and to get cycle count when starting the hot code.