Why is SegmentStatistics slower in Python console?

SegmentStatistics computation runs at least at half speed in the Python console than in the module’s widget.

With a single segment drawn with the Paint tool at 3% and a sphere brush, the execution time is 0.40 secs in the module’s widget and 1.08 secs in the Python console with the following call :

import SegmentStatistics
segmentation = slicer.util.getNode("Segmentation")
volume = slicer.util.getNode("CTA-cardio")
logic = SegmentStatistics.SegmentStatisticsLogic()
logic.getParameterNode().SetParameter("Segmentation", segmentation.GetID())
logic.getParameterNode().SetParameter("ScalarVolume", volume.GetID())
logic.computeStatistics()

The difference increases more than twofold with multiple segments.

It’s not a fundamental issue requiring a fix in the module itself, I’m more interested to know if it can be remedied by the caller in his code.

Thank you for any suggestion.

Fixed in this commit, and it’s really fast, thanks.