Benchmarking
With os.clock
, you can compute (just about) the CPU time taken to execute a chunk of code.
By saving the time before starting the code and subtracting the before from the time after it executes, you get an approximate amount of seconds taken to execute that chunk of code.
Here's a benchmarking function to help with determining the performance of code:
unit
: Unit of time to show the result in ('seconds', 'milliseconds', 'microseconds', or 'nanoseconds')decPlaces
: Number of decimal places to use when showing the elapsed timen
: Number of times to run the functionf
: Function to run...
: Arguments passed to functionf
Example of using it from the previous page:
Output of the above:
Last updated