3 ms·
Counting instructions properly is hard and also results in a good amount of overhead if you don't use a bunch of tricks or a kernel module. You also can't real
by mhh__ 5y ago
Counting instructions properly is hard and also results in a good amount of overhead if you don't use a bunch of tricks or a kernel module.
You also can't really count instructions in the cloud.
- wooosh 5y agoCounting (userspace) instructions is relatively easy regardless of language with perf stat, though it does require the kernel module. Generally speaking it should just work if perf is installed through the package manager for your distribution. edit: valgrind's callgrind utility can also produce exact instruction execution counts for a given block of code
- mhh__ 5y agoCallgrind can give you instruction counts yes. It doesn't simulate any microarchitecture other than caches which means its only useful for comparing with itself. Perf stat is very very high overhead. The perf API is available and can be tuned a bit more nicely but it's mostly a horrible mess. It uses bitfields too which makes it somewhat hard to get to from other languages unless you trust the shifts and masks.