If there was no benefit to us in enduring through pain and sorrow, it would truly make no sense for our loving heavenly Father to permit even a moment of it. But the Scriptures insist that suffering is never meaningless. Suffering always produces something. So Paul can say with confidence that “this light momentary affliction is preparing for us an eternal weight of glory beyond all comparison” (2 Cor. 4:17). He knows that “suffering produces endurance, and endurance produces character, and character produces hope, and hope does not put us to shame, because God's love has been poured into our hearts through the Holy Spirit who has been given to us.” (Romans 5:3-5). Even more boldly, the Psalmist can say in Psalm 119:
The law of your mouth is better to me
than thousands of gold and silver pieces.
His suffering revealed something far better and more precious, which became a greater comfort to him than if he had never been afflicted. God's purposes are always to make things better, or to restore them when they are damaged. "Physicians, though they put their patients to much pain, will not destroy nature, but raise it up by degrees. Surgeons will lance and cut, but not dismember. A mother who has a sick and self-willed child will not therefore cast it away. And shall there be more mercy in the stream than in the spring? Shall we think there is more mercy in ourselves than in God, who plants the affection of mercy in us?" (Richard Sibbes, The Bruised Reed, Chapter 2). Seeing God's purpose as healing and restoration doesn't eliminate the pain, but it assures you that what you want and what your doctor wants are the same thing. You're not being subjected to suffering needlessly or for no benefit, and it isn't random. The author of Psalm 119 takes confidence and comfort from knowing that "in faithfulness you have afflicted me." (Psalm 119:75).
One way to understand God's faithfulness in our suffering is knowing and trusting that God diligently watches over our suffering and makes sure there is not one more moment than is necessary for our good. He vigilantly prevents any unneeded suffering, because "a Father’s love is joined with infinite wisdom, ...therefore, every ingredient in the bitter cup is measured out drop by drop, and grain by grain, and there is not one pang too many ever suffered by an heir of heaven. The cross is not only weighed to the pound, but to the ounce, ay, to the lowest conceivable grain. You shall not have one half a drop of grief more than is absolutely needful for your good and God’s glory. And does not this also sweeten the cross, that it is laid on us by infinite wisdom, and by a Father’s hand?" (Charles Spurgeon, courtesy of Banner of Truth Press (emphasis added)).
Spurgeon gained this confidence from knowing the character and heart of the one who measured out his sorrows and pain. The heart of Jesus is shown in the promise that “a bruised reed he will not break, and a faintly burning wick he will not quench[.]” (Isaiah 42:3). Richard Sibbes unpacks the wonderful comfort of these words throughout The Bruised Reed, which has reassured and comforted saints including Richard Baxter and D. Martyn Lloyd-Jones in the midst of doubt and sorrow. Sibbes assures us that "Christ will not break the bruised reed, nor quench the smoking flax, in which more is meant than spoken, for he will not only not break nor quench, but he will cherish those with whom he so deals." Christ isn't merely gentle with us; He is lovingly and earnestly devoted to us. The more you learn to know His heart as revealed throughout the Bible, the more you increase your trust in the one who measures every ounce of your joy and pain. This hymn is a great help to me in remembering this.
Gives unto each day what He deems best,
Lovingly its part of pain and pleasure,
Mingling toil with peace and rest.