Why Julia is so much slower than Python? Invitation to Euler Project

BTW:

julia> factorial_digit_sum(n::Int64) = n |> big |> factorial |> digits |> sum

julia> @benchmark factorial_digit_sum(100)
BenchmarkTools.Trial: 
  memory estimate:  30.80 KiB
  allocs estimate:  1415
  --------------
  minimum time:     44.063 μs (0.00% GC)
  median time:      49.813 μs (0.00% GC)
  mean time:        98.234 μs (31.32% GC)
  maximum time:     117.051 ms (74.85% GC)
  --------------
  samples:          10000
  evals/sample:     1

A bit of type piracy, and then:

julia> Base.digits(b::BigInt) = [c - '0' for c in string(b)]

julia> @benchmark factorial_digit_sum(100)
BenchmarkTools.Trial: 
  memory estimate:  1.86 KiB
  allocs estimate:  14
  --------------
  minimum time:     1.659 μs (0.00% GC)
  median time:      1.925 μs (0.00% GC)
  mean time:        2.447 μs (7.45% GC)
  maximum time:     1.362 ms (35.47% GC)
  --------------
  samples:          10000
  evals/sample:     10
1 Like