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.
You also can't really count instructions in the cloud.
edit: valgrind's callgrind utility can also produce exact instruction execution counts for a given block of code
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.