# itk-python weird time consuming

**URL:** https://discourse.itk.org/t/itk-python-weird-time-consuming/4975
**Category:** Beginner Questions
**Tags:** python
**Created:** [May 10, 2022, 3:37am UTC](https://discourse.itk.org/t/itk-python-weird-time-consuming/4975 "2022-05-10T03:37:26Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![HiunIce](https://discourse.itk.org/user_avatar/discourse.itk.org/hiunice/32/2674_2.png) [@HiunIce](https://discourse.itk.org/u/HiunIce)
#### Post date: [May 10, 2022, 3:37am UTC](https://discourse.itk.org/t/itk-python-weird-time-consuming/4975/1 "2022-05-10T03:37:26Z")

</div>

Hi teams,

I tried some itk.filter both in cpp and python.  
The cpp version is ok but python version is quite time consuming(for New statement)  
‘’’

# cost 15 second for this code

itk.RescaleIntensityImageFilter[self.inputType, self.outputType].New()

# cost 4 second for this code

itk.CenteredEuler3DTransform[itk.D].New()  
‘’’

Is there any ways to fix it or avoid it?

Thank you!

Best regards

---

<div class="post-metadata">

### Author: ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)
#### Post date: [May 13, 2022, 9:48am UTC](https://discourse.itk.org/t/itk-python-weird-time-consuming/4975/2 "2022-05-13T09:48:46Z")

</div>

Hi @HiunIce ,

Welcome to the ITK community! 🌞

The delay is related to loading library dependencies in Python. At the beginning of your Python session, call `itk.force_load()` (will take some time the first time), and subsequent calls to `.New()` will be faster. Due to OS caching, subsequent calls even after exiting an interpreter will be faster.

Hope this helps,  
Matt

---

<div class="post-metadata">

### Author: ![HiunIce](https://discourse.itk.org/user_avatar/discourse.itk.org/hiunice/32/2674_2.png) [@HiunIce](https://discourse.itk.org/u/HiunIce)
#### Post date: [May 13, 2022, 10:00am UTC](https://discourse.itk.org/t/itk-python-weird-time-consuming/4975/3 "2022-05-13T10:00:49Z")

</div>

Thanks your reply, it runs faster after the first calling.  
But my interpreter seems do not save any cache for it, when I rerun the script(ctrl+F10 in pycharm), it will runs force\_load() again.  
I am using pycharm for windows10.

Thank you.

---

<div class="post-metadata">

### Author: ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)
#### Post date: [May 13, 2022, 10:15am UTC](https://discourse.itk.org/t/itk-python-weird-time-consuming/4975/4 "2022-05-13T10:15:25Z")

</div>

Hi,

PyCharm does some additional processing to try to understand the code. @hjmjohnson @kjweimer made contributions in the upcoming 5.3rc4.post1 release that improves type annotations for IDE’s like PyCharm. I do not know whether it will improve PyCharm’s preprocessing times, but you may try to see if improves your experience.

---

<div class="post-metadata">

### Author: ![HiunIce](https://discourse.itk.org/user_avatar/discourse.itk.org/hiunice/32/2674_2.png) [@HiunIce](https://discourse.itk.org/u/HiunIce)
#### Post date: [May 13, 2022, 12:20pm UTC](https://discourse.itk.org/t/itk-python-weird-time-consuming/4975/5 "2022-05-13T12:20:08Z")

</div>

Thanks a lot!
