Is microcontroller power consumption directly related to its operation time?
Kind of. What draws most current is the CPU clock and any active hardware peripherals such as GPIO. Hardware peripherals being a story of their own since each one has unique power consumption characteristics.
There is of course a direct relation between CPU clock cycles needed and the length of the machine code executed, so there is also a relation between CPU clock cycles and current consumption.
This given that you utilize sleep modes when you aren't running any code, or otherwise it is pointless to speak of algorithm current consumption.
The efficiency of the algorithm, the "code efficiency" of the CPU and the hardware current consumption per tick all play part. Code efficiency in this case means how many CPU ticks it takes to execute a certain piece of higher layer program code (C code etc).
For example, some people argue that 8 bit MCUs should still be used because they draw less current than 32 bit ones. This tends to be true if you look at peak current consumption, but not necessarily so if you look at current consumption over time.
Take something like the C code
my_uint32 = u32a + u32b;. The average 32 bit CPU will execute that line in a few assembler instructions, which perhaps means somewhere around 10-20 CPU ticks. An 8 bit MCU however, will need hundreds of assembler instructions in the form of software libs to execute the same code. Maybe 500-1000 CPU ticks, very roughly counted. So it could take the 8 bitter as much as around 100 times more execution speed/current consumption to run the very same code. And then it is suddenly irrelevant that the MCU draws less current per tick compared to the 32 bitter.