Foka answer is spot-on for diesel engines with DPF. The same reasoning, to a lesser degree, apply to gasoline engines too.
You won't gain power or torque, not in a perceptible way.
But driving a car in a "spirited" way make it run smoother. How, and how much this is relevant, depends on the age of the car.
Of course, as Glen Jaron pointed out, the car needs to be "ready", which means run-in AND also ready for hard driving (which means that the OIL must be warm; warm coolant is not enough).
A car not running as it should may be partly due to carbon deposits, that will be cleared and burned by the higher temperatures reached when running at higher revs
One of the reasons (probably, the prominent reason) of carbon deposits is linked to the stoichiometric ratio, especially in older cars. In fact, this gets more important as the car gets older.
The stoichiometric ratio is the ideal mixture of fuel to air link, wikipedia
Carburetors on older cars (and ECUs in newer injection systems, with or without lambda sensors) have the purpose of reaching this mix in which there is just enough air present in order to burn off all of the fuel, although it’s never 100% achieved.
The typical stoichiometric mixture ratio a carburetor (or fuel injection) has to achieve when mixing fuel and air is 14.7 of air mass to 1 of fuel mass – 14.7 : 1.
If the stoichiometric mixture is lower then this means the engine will be running fuel rich which means fuel is wasted, engine emissions will be higher and "dirt" (carbon residues) will accumulate.
If the stoichiometric ratio is higher then this means that the engine will be running lean and will struggle to give a smoother running performance, struggle to maintain combustion and possibly (in extreme cases) permanent damage to the piston's heads. (Lean mixture -> detonation -> Chamber too hot -> hole in piston
When the engine is "cold" (at start, or if it run very conservatively)
the mixture is richer, to prevent engine hesitation and damage (for multiple reasons: the oxygen sensor (MAF, IAF, or whichever sensor you have) operates in a good reliable way only when temperatures are high, a richer mixture helps protect the engine, etc.)
In older ECUs this is quite important (see for example the Bosch Motronic); in modern ECUs this is far less.
It is believed (by ECUs reverse engineers) that ECUs do not learn the driving style. However, they have still to prepare the right mix, and they do learn "fuel quality".
Finally, modern engines also suffer from carbon deposit due to a different injection mechanism direct injection. Getting the combustion chamber hot (higher revs) helps in this situation as well.