# CPU cycles and syscalls

**URL:** <https://discourse.julialang.org/t/cpu-cycles-and-syscalls/20702>\
**Category:** Performance\
**Tags:** performance\
**Created:** [February 12, 2019, 2:13pm UTC](https://discourse.julialang.org/t/cpu-cycles-and-syscalls/20702 "2019-02-12T14:13:56Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![varleg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/varleg/32/7064_2.png) [@varleg](https://discourse.julialang.org/u/varleg)\
**Post date:** [February 12, 2019, 2:13pm UTC](https://discourse.julialang.org/t/cpu-cycles-and-syscalls/20702/1 "2019-02-12T14:13:56Z")

</div>

Hello.  
I am doing a project on Julias performance compared to assembly, C and FPGA rpogramming. The thing I have noticed thus far is:  
Julia uses 300,000,000 cycles and 130.7 msec to calculate 2+2  
C uses 290,000 cycles and 0.37 msec  
I am using perf stat to do my measurments.  
How can I improve Julias performance, or get more accurate measurements? Is it possible to compile a Julia binary so I dont have to call de JIT compiler on every run?

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [February 12, 2019, 2:51pm UTC](https://discourse.julialang.org/t/cpu-cycles-and-syscalls/20702/2 "2019-02-12T14:51:02Z")

</div>

```julia

julia> @btime 2+2
  0.001 ns (0 allocations: 0 bytes)
4

```

I’m not sure that this is a terribly useful benchmark - it might be more meaningful to measure operations that your application actually spends a significant amount of time on performing?

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [February 12, 2019, 2:59pm UTC](https://discourse.julialang.org/t/cpu-cycles-and-syscalls/20702/3 "2019-02-12T14:59:19Z")

</div>

> [@nilshg](#):
>
> ```julia
> julia>@btime 2+2 0.001 ns (0 allocations: 0 bytes) 4
> 
> ```

This is due to constant propagation. A single addition operation is not meaningful to measure but it at least doesn’t take 0.001 ns.

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [February 12, 2019, 3:48pm UTC](https://discourse.julialang.org/t/cpu-cycles-and-syscalls/20702/4 "2019-02-12T15:48:37Z")

</div>

Agree it was a silly example - but goes to show that one can do `2+2` in Julia in less than 300 million (!?) cycles. It was rather meant to prompt OP to provide a bit more context to understand how he arrives at the conclusion that Julia is slower than C by a factor of 350 for adding integers.

---

<div class="post-metadata">

**Author:** ![varleg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/varleg/32/7064_2.png) [@varleg](https://discourse.julialang.org/u/varleg)\
**Post date:** [February 12, 2019, 4:19pm UTC](https://discourse.julialang.org/t/cpu-cycles-and-syscalls/20702/5 "2019-02-12T16:19:54Z")

</div>

The purpose ultimately is showing pros and cons of synthesized hardware regarding calculations. My proposed calculation is Fibonacci sequences, and this addition test was just to see if the experiment is viable. My idea is to implement he same algorithm in fpga , Julia and in my Xilinx fpga and compare cpu usage , time , operations , cycles etc.
