Of course.
You look like you are right there on top of it...
get the time now. save it as start time.
run the code.
get the time now again.
Difference = run time.
if the code executes so fast this is zero every time, look at other posts here and on google about high resolution timers, be sure that whatever you look at is in the last couple of years. Most timers can only measure large chunks (compared to PC clock speeds --- as Data said in trek... for an android it was an eternity ...)
if you want an average done for you (vs manually tracking in excel or something) you
for(bunch of runs)
{
get start
run
get end
get diff, add to total
}
avg = total/bunchofruns
I forgot to say... if the code runs in a loop normally the above works. If it is run here and there at different times between other code, that isnt accurate because of caching and paging and other things. Basically code runs faster when you run the same code again, and slower if something is between runs, for a variety of reasons.