@time returns a negative value

@time should never be able to report a time of nothing. The actual return value of @time is just the value of the expression and has nothing to do with the time it took to execute. That time is printed but never returned.

julia> a = @time 3-4
  0.000001 seconds
-1

julia> a
-1

I suspect you’re trying to read the output of @time into a variable. Perhaps you are looking for @elapsed?

julia> b = @elapsed 3-4
5.0e-7 # this is how long the expression took to execute, in seconds
5 Likes