It would deter if carried out in a timely manner.
15-20+ years is not timely. The chance of them escaping and killing or maiming is also greatly reduced once they assume room temperature. Repeat child molesters would also be a thing of the past if it were a capital offence.
