Benchmarking

For benchmarking purposes, we already know @time and @elapsed; @timed gives you the @time results as a tuple:

@time [x^2 for x in 1:1000] prints elapsed time: 3.911e-6 seconds (8064 bytes allocated) and returns 1000-element Array{Int64,1}: ....

@timed [x^2 for x in 1:1000] returns the following:

([1, 4, 9, 16, 25, 36, 49, 64, 81, 100 ... 982081, 984064, 986049, 988036, 990025, 992016, 994009, 996004, 998001, 1000000], 3.911e-6, 8064, 0.0)

@elapsed [x^2 for x in 1:1000] returns 3.422e-6.

If you are specifically interested in the allocated memory, use @allocated [x^2 for x in 1:1000], which returns 8064.

If you are looking for a package, consult BenchmarkingTools. This has some macros and also a good method for benchmarking.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.21.46.78