# Why is SegmentStatistics slower in Python console?

**URL:** https://discourse.slicer.org/t/why-is-segmentstatistics-slower-in-python-console/31379
**Category:** Support
**Created:** [August 26, 2023, 12:57pm UTC](https://discourse.slicer.org/t/why-is-segmentstatistics-slower-in-python-console/31379 "2023-08-26T12:57:50Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![chir.set](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/chir.set/32/66982_2.png) [@chir.set](https://discourse.slicer.org/u/chir.set)
#### Post date: [August 26, 2023, 12:57pm UTC](https://discourse.slicer.org/t/why-is-segmentstatistics-slower-in-python-console/31379/1 "2023-08-26T12:57:50Z")

</div>

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 :

```auto
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.

---

<div class="post-metadata">

### Author: ![chir.set](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/chir.set/32/66982_2.png) [@chir.set](https://discourse.slicer.org/u/chir.set)
#### Post date: [July 1, 2024, 8:12am UTC](https://discourse.slicer.org/t/why-is-segmentstatistics-slower-in-python-console/31379/2 "2024-07-01T08:12:11Z")

</div>

Fixed in this [commit](https://github.com/Slicer/Slicer/commit/453c5befb470bc20ac69dfa06a5f404a85b9f092), and it’s really fast, thanks.
