The sonnets contrast with each other on subject, underlying metaphor, entity being addressed along with problem and solution. On the other hand, they compare with each other in regard to optimistic tone and on the thematic topic of eternal life, although they contrast once again on the means of attaining eternal life.
In Donne's sonnet, "Death Be not Proud, Holy Sonnet 10," the subject is the real or feigned power of a personified Death. Donne asserts that Death's power is feigned. The underlying metaphor is the comparison of Death to a pleasant refreshing sleep. The entity being addressed by the poem is Death, itself. The problem or situation presented in the octave is that Death has no power to kill the speaker and that those who Death takes are only resting. The solution presented in the sestet is that Death is the pawn of fate and kings and that when the dead awake to eternal life, then Death itself shall die.
In Shakespeare's "Sonnet 31," the subject is the nature of the poetic speaker's beloved in whom all hearts reside and who is Love personified. The underlying metaphor compares past loves lost to death with the quality of all-encompassing love in the present beloved. The person being addressed is the living beloved. The problem or situation presented in the octave is the tears of mourning shed for lost loves that now are accumulated in the beloved. The solution presented in the sestet is that the beloved, who embodies all who have preceded, is now the sole recipient of the speaker's love and devotion.
Both speak of eternal life, Donne's of eternal life through victory over Death, a victory in which Death will die, and Shakespeare's of eternal life through metaphorical resurrection through the all-encompassing qualities of the newly beloved one. The final contrast is that Donne is theologically serious while Shakespeare is entirely metaphorical.
The rhyme scheme of Donne's marks it as a Petrarchan sonnet in an a b b a a b b a c d d c e f scheme with no rhyming end couplet, while the rhyme scheme of Shakespeare's marks it as a Shakespearean sonnet, which is an innovation on the Petrarchan sonnet. It is in an a b a b c d c d e f e f gg scheme with a rhyming end couplet. Both sonnets have subject changes at the fifth and ninth lines as established by Petrarch as the definitive sonnet structure. In Donne's the changes, or turns (called voltas), are from those who have died to (5) the metaphor of sleep for death to (9) Death being the slave of kings and chance, etc. In Shakespeare's, the turns are from Love to (5) the speaker's tears for those past to (9) the new love being the grave of the past loves, their embodiment, their completion.