# Python's replace faster than Julia's replace?

**URL:** <https://discourse.julialang.org/t/pythons-replace-faster-than-julias-replace/63180>\
**Category:** General Usage\
**Tags:** strings, regex, python\
**Created:** [June 19, 2021, 12:00pm UTC](https://discourse.julialang.org/t/pythons-replace-faster-than-julias-replace/63180 "2021-06-19T12:00:50Z")\
**Posts on this page:** 3\
**Page:** 2

<div class="post-metadata">

**Author:** ![yolhan\_mannes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yolhan_mannes/32/220485_2.png) [@yolhan\_mannes](https://discourse.julialang.org/u/yolhan_mannes)\
**Post date:** [October 7, 2025, 4:18pm UTC](https://discourse.julialang.org/t/pythons-replace-faster-than-julias-replace/63180/21 "2025-10-07T16:18:29Z")

</div>

I guess replace has a fold back method and there is no special implementation for Inline Strings ? Or the constructor of InlineString has to copy the data to new memory ?

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [October 7, 2025, 10:48pm UTC](https://discourse.julialang.org/t/pythons-replace-faster-than-julias-replace/63180/22 "2025-10-07T22:48:04Z")

</div>

> [@yolhan\_mannes](#):
>
> I guess replace has a fold back method and there is no special implementation for Inline Strings ?

`replace` uses an `IOBuffer` to build up the new string — it’s not simply a `fold` call — but every iteration of this benchmark is calling `replace` to allocate a new little string. And it’s not specialized for InlineStrings.jl.

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [October 7, 2025, 10:50pm UTC](https://discourse.julialang.org/t/pythons-replace-faster-than-julias-replace/63180/23 "2025-10-07T22:50:46Z")

</div>

> [@yolhan\_mannes](#):
>
> Can you try on 1.12 ?

I tried it on a recent build of 1.13, and it was about the same speed.

[Previous page](https://discourse.julialang.org/t/pythons-replace-faster-than-julias-replace/63180.md?page=1)
