For example, if we want to evaluate the time cost of the following code snippet:

total = 0
for i in 1:100000000
total += i
end

Standard practice is as follows (right?): First, write it into a function:

function mysum()
total = 0
for i in 1:100000000
total += i
end
end

Then, run the function once and time it to trigger compilation:

@time mysum()

Finally, run again, formally timing it:

@time mysum()

Now in the REPL we can see the time cost: 0.000001 seconds. However, in many cases, we need to store this time for subsequent analysis. Then how do we record the return value of @time into a variable and store it?

If the function contains a pmap parallel mechanism internally, and we increase the number of workers by 5, i.e.using Distributed; addprocs(4), then in order to evaluate the running time of this function, should we ensure that the function has been pre-run on each worker?

If I add 4 workers, and now there are 5 workers in total, and then I run a program that contains two functions, the first function contains pmap parallel, and the second function is a thorough serial program. Then, I know that the first function is completed by multiple workers, and my question now is whether we can explicitly know which worker runs the second function?

If the serial function is randomly assigned to an idle worker to run, how do we ensure that this serial function is pre-run and compiled on each worker?