A gasoline engine adds its heat in a sudden bang at the top of the stroke (constant volume); a diesel adds it more gently while the piston starts moving down (constant pressure). At the same compression ratio the gasoline cycle wins. But knock stops a gasoline engine near a ratio of 10, while a diesel happily runs 18 or more, and that's why diesels come out ahead in practice.