Julia execution speed

I am comparing the execution speed of Julia. I executed @time [i^2 for i in 1:1000]

on Julia's prompt, which resulted in something on the order of 20ms. This seems odd since my computer is modern with an i7 processor (I'm using Linux Ubuntu).

Another strange thing: when I execute the same command in the range 1:10

, the execution time is 15ms.

There must be something trivial I'm missing here?

+3


source to share


1 answer


Several things, see performance tips :

  • Don't check global capabilities.
  • Don't measure first execution with something like this.
  • Use BenchmarkTools .


Julia is a JIT compiled language, so when you first measure things, you measure the compile time. This is a small, fixed overhead, so for anything that takes a significant amount of time it is negligible, but for short code like this, almost all the time. Volatile globals cause the compiler to assume almost nothing about types, which tends to poison your entire performance. This is fine in some cases, but in most cases, you should a) write code so that the inputs are explicit function parameters rather than implicit parameters coming from some global variables, and b) should not write code that uses mutable global state.

+8


source







All Articles