How to measure time taken by a function in C?

I’ve tried to use some code I’ve found here on the forums but they include a library called “enconding.h” and I simply can’t find that on the current version of the SDK.

Since I am making a topic, I also want to ask if it is possible (and how to do it) to measure the number of instructions and the memory utilized by a function, as well as the energy consumed.

Thank you very much.

You’ll need to use the instret/minstret and cycle/mcycle registers. Read them before and after then subtract to get the total number of instructions and cycles used. The registers starting with m are for machine mode access, where the others can be available from user mode if you enable the mcounteren::ir bit. Energy consumed would probably need an external IC to measure.