Counting (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