The time in Purgatory would depend on the amount of temporal punishment you have at the moment of your death.
Each of us has a running account of temporal punishment. When you commit a mortal sin and are absolved, you still have to do some penance to atone for the temporal punishment left over from that. Also, venial sins incur temporal punishment for us too.
If you confess your sins, mortal and venial, in confession, you are put in sanctifying grace, and the sacrament removes some of your temporal punishment for the venial sins, but not necessarily all of it. And mortal sins come with a lot more temporal punishment since they are much more serious. This temporal punishment must be atoned for as well, even after absolution.
You pay down your debt of temporal punishment by attending Mass (the most effective way), voluntary mortifications, patiently enduring suffering for the love of God, getting indulgences, good works, receiving the sacraments, and similar good actions.
When you die, any temporal punishment you have not yet paid off becomes the suffering you have to endure in Purgatory. And it's important to pay off as much temporal punishment as you can in this world, because you get a lot less credit for the pains of Purgatory, in terms of canceling temporal punishment, than you do for suffering in this world.