Is microcontroller power consumption directly related to its operation time?
There are many things that alter the power consumption of the device, but assuming your just computing an algorithm with all unused peripherals switching off, e.g. ADC (pulsing current each sample), GPIO (changing state consumes a small amount of current), watchdog circuit disabled (runs a clock and triggers an interrupt), 

Then yes, the longer something takes to compute, the more power it has consumed, there is a trade off between clock speed and total power consumption (for most devices running at the highest clock speed for the shortest time uses less energy than a slower clock for a longer time) however again assuming that all stays the same, longer time = more power

If you want to start including other peripherals, towards the bottom of the datasheet for your device you will find chart after chart after chart outlining what the power consumption is for your particular use case, and various other relations, e.g. if you have the pin pullup left on, how long your switching that pin low increases consumption, if your driving something else in the signal, it will consume something in both high and low states, if your using ADC's, then the input buffers will have a non linear current draw depending on the input voltage. (usually you would disable them)