I am looking for some ideas for short example codes which can be used to demonstrate how much time it takes for Julia to compile when code is first run vs the time taken for code to execute after it has been run once (and hence compiled).
There is a question on Stack Overflow about this. I provide the link here.
However, on modern machines, it appears that this takes less than 0.000000 seconds
to compile and run. Hence the demo doesn’t work on a fast modern CPU.
Does anyone have an idea for some relatively simple code which could be used to demonstrate the difference between running
- the first time (which includes compilation)
- subsequent runs (where the code has previously been compiled)
I am looking to demonstrate a few things:
- How much faster a function can be made using
__precompile__()
- How much faster a function can be made by using
__precompile__()
and running the function by calling it (see example below:# precompile hints
)
__precompile__()
module TestPackage
export cube
square(x) = x * x
cube(x) = x * square(x)
# precompile hints
cube(0)
end
I appreciate this is a bit of a vague or open-ended question. Whatever is being compiled needs to be simple enough to be easy to understand but complex enough to actually spend a reasonable amount of time (maybe ~ 0.01 sec) compiling.
Any suggestions gratefully received. I’m sort of hoping someone already has done this experiment and can provide some relatively minimal-effort-required pre-made example.