# General questions from Python user

**URL:** <https://discourse.julialang.org/t/general-questions-from-python-user/55475>\
**Category:** Performance\
**Created:** [February 17, 2021, 5:23pm UTC](https://discourse.julialang.org/t/general-questions-from-python-user/55475 "2021-02-17T17:23:32Z")\
**Posts on this page:** 1\
**Showing post:** 38

<div class="post-metadata">

**Author:** ![Mason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mason/32/2423_2.png) [@Mason](https://discourse.julialang.org/u/Mason)\
**Post date:** [February 23, 2021, 12:29am UTC](https://discourse.julialang.org/t/general-questions-from-python-user/55475/38 "2021-02-23T00:29:00Z")

</div>

> [@jling](#):
>
> that, in these practices Python will be slow too (due to similar reason, being a dynamic language itself) and very often slower than Julia:

It can sometimes carry a higher cost in julia however.

If you’d like an example, here’s an example from [this thread](https://discourse.julialang.org/t/why-is-python-faster-than-julia/35890/5):

```julia
In [6]: def euclidian_algorithm_division_count(a, b):
   ...: division_count = 1
   ...: if b > a:
   ...: a, b = b, a
   ...: while (c := a % b) != 0:
   ...: a, b = b, c
   ...: division_count += 1
   ...: return division_count
   ...: 
   ...: from random import randint

In [7]: %%timeit
   ...: N = 10**100
   ...: M = 10**4
   ...: division_count_array = []
   ...: while M > 0:
   ...: a = randint(1, N)
   ...: b = randint(1, N)
   ...: division_count_array.append(euclidian_algorithm_division_count(a, b))
   ...: M -= 1
292 ms ± 7.74 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)

```

```julia
julia> function euclidean_algorithm_division_count(a, b)
           division_count = 1
           if b > a
               a, b = b, a
           end
           while (c = a % b) != 0
               a, b = b, c
               division_count += 1
           end
           return division_count
       end
euclidean_algorithm_division_count (generic function with 1 method)

julia> function main()
           N = big(10)^100
           M = 10^4
           division_count_array = []
           while M > 0
               a, b = rand(1:N, 2)
               push!(division_count_array, euclidean_algorithm_division_count(a, b))
               M -= 1
           end
       end
main (generic function with 1 method)

julia> @btime main()
  378.040 ms (5618922 allocations: 110.55 MiB)

```

It’s of course not very hard to make the julia version beat the Python version, but this straightforward transcription (that even uses a function) of naive Python code can still be slower in julia.

---

_[View the full topic](https://discourse.julialang.org/t/general-questions-from-python-user/55475)._
