# Comparing Sum function from multiple languages

**URL:** <https://discourse.julialang.org/t/comparing-sum-function-from-multiple-languages/67305>\
**Category:** New to Julia\
**Tags:** discussion\
**Created:** [August 29, 2021, 6:58pm UTC](https://discourse.julialang.org/t/comparing-sum-function-from-multiple-languages/67305 "2021-08-29T18:58:38Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![hdcpereira](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hdcpereira/32/28705_2.png) [@hdcpereira](https://discourse.julialang.org/u/hdcpereira)\
**Post date:** [August 29, 2021, 6:58pm UTC](https://discourse.julialang.org/t/comparing-sum-function-from-multiple-languages/67305/1 "2021-08-29T18:58:38Z")

</div>

Hello there.

I’ve finished the juliaacademy course on the basics of julia and it ends with a very nice comparision of the sum function across multiple languages. I’ve changed some few things in the original code, now I’m getting the average time that the benchmarks function returns and also, i’m properly plotting it.

Just like @jling sugested, i will try to write some improvements in this code.

Here is the plot and the [code](https://github.com/hdcpereira/aprendendo-julia/blob/main/how_fast_is_julia_sum.ipynb).

![howdy](https://global.discourse-cdn.com/julialang/original/3X/4/d/4d8d179aa05531262d6ece9a391084ba8468ceb6.png)

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [August 29, 2021, 7:00pm UTC](https://discourse.julialang.org/t/comparing-sum-function-from-multiple-languages/67305/2 "2021-08-29T19:00:20Z")

</div>

you don’t need to post multiple times. `sum` is a completely solved problem basically, and implementation, even in C, is still pretty trivial, so I suggest you compare something slightly more interesting.

---

<div class="post-metadata">

**Author:** ![hdcpereira](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hdcpereira/32/28705_2.png) [@hdcpereira](https://discourse.julialang.org/u/hdcpereira)\
**Post date:** [August 29, 2021, 7:02pm UTC](https://discourse.julialang.org/t/comparing-sum-function-from-multiple-languages/67305/3 "2021-08-29T19:02:20Z")

</div>

it’s been a very good exercise though 😉

---

<div class="post-metadata">

**Author:** ![xinchin](https://avatars.discourse-cdn.com/v4/letter/x/54ee81/32.png) [@xinchin](https://discourse.julialang.org/u/xinchin)\
**Post date:** [August 30, 2021, 1:32am UTC](https://discourse.julialang.org/t/comparing-sum-function-from-multiple-languages/67305/4 "2021-08-30T01:32:47Z")

</div>

used your code and my results show julia hand written is faster than numpy! good exercise for me too  
median(py\_numpy\_bench.times) / 1e6  
3.498948  
median(j\_bench\_hand.times) / 1e6  
3.057931

---

<div class="post-metadata">

**Author:** ![lungben](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lungben/32/12314_2.png) [@lungben](https://discourse.julialang.org/u/lungben)\
**Post date:** [August 30, 2021, 6:53am UTC](https://discourse.julialang.org/t/comparing-sum-function-from-multiple-languages/67305/5 "2021-08-30T06:53:34Z")

</div>

Yes, a naive hand-written sum in Julia is faster than the built-in one. But it is less precise (for floats), the built-in sum uses pair-wise summation.
