Python's replace faster than Julia's replace?

alasaadstat
Sat, 19 Jun 2021 12:00:50 +0000
General Usage

Hi, I am currently working on regex stuffs, and I noticed that Python’s replace seems to be faster than Julia’s replace.

function test(iter=100_000)
    for _ in 1:iter
        replace("The quick foxes run quickly.", r"fox" => s"bus")
    end
end

@time test(10_000_000)
# 6.720898 seconds (90.00 M allocations: 4.321 GiB, 2.32% gc time)

and for Python,

import timeit

def test(iter=100_000):
    for i in range(iter):
        "The quick foxes run quickly.".replace(u"fox", u"bus")

timeit.timeit('test(10_000_000)', setup="from __main__ import test", number=1)
# 1.6722020990000601 seconds

Am I missing something?

23 posts - 8 participants