For the same average gradient and same constant power output, and assuming same bike, same tires, and zero wind the variable grade climb will take longer than a constant grade climb.
The reason is that with constant power and a variable gradient, you go faster when it's shallower (and slower when it's steeper) but aerodynamic drag increases with the square of air speed so you don't gain as much speed on the flatter parts as you lose on the steeper parts.
Suppose you were comparing two climbing routes: route A is a constant 5% over 3 km; route B is flat for 1.5 km, then climbs at 10% for 1.5 km. Both have a total length of 3 km, and both climb a total of 150 meters. Ignore for the moment the difference between road distance and horizontal distance.
At a constant 250 watts, the same CdA = 0.3 m^2, the same Crr = 0.005, rho = 1.2 kg/m^3, and total rider+bike mass of 80kg, the average speed for route A is 5.21 m/s, or a total time of 576 seconds.
For route B, the speed along the flat section is 10.51 m/s and the speed along the 10% gradient section is 2.98 m/s, for a total time of 646 seconds.
The above is just an extreme example but the same principles and calculations apply for any combination of gradients. That said, the smaller the range of grades around the average grade, the smaller is the difference between a climb at a constant average grade and a variable grade. For the example above where the average grade is 5% but half of the route was 0% and half at 10%, the difference in total time is 70 seconds. If, instead, half the route was at 4% and half at 6%, the difference in total time would be 3 seconds. This should not be surprising: the closer the variable grade is to a constant grade, the closer the two time estimates will be. That there is any difference at all is due to the nonlinearity of aerodynamic drag with speed, so any difference in speed for the shallower and steeper parts of the climb won't balance out.
Although you did not ask the question, constant power on route B is not the fastest way to do this climb. Constant power is time-minimizing only when the conditions are also constant so a time-minimizing strategy for variable gradient (or variable wind, or variable surfaces) is to vary the power. There are physiological constraints, of course, on how much you can vary the power so the optimization problem can be complex.
As an aside, I have spent some time examining the inverse question: given power and speed, can we calculate variable grade? Then I look at the calculated variable grade and find the drag parameters (CdA and Crr) that make the calculated grades match the actual road. This method of estimation appears to work well.