Skip to content

Instantly share code, notes, and snippets.

@MrPandir
Created April 15, 2025 13:50
Show Gist options
  • Save MrPandir/497bb713baa04f46a1304e7587c7493c to your computer and use it in GitHub Desktop.
Save MrPandir/497bb713baa04f46a1304e7587c7493c to your computer and use it in GitHub Desktop.
Nushell performance measurement utility
# Measures the average execution time of a specified function over a given number of iterations
export def main [
func: closure # The function (closure) to be executed
iterations: int = 10000 # Number of iterations to run the function
] {
let start_time = date now
1..($iterations) | each { |_| do $func } | ignore
let end_time = date now
let total_execution_time = $end_time - $start_time
let average_execution_time = ($total_execution_time | into duration) / $iterations
$"Average execution time: ($average_execution_time)"
}
# Import as:
# use measure.nu
@MrPandir
Copy link
Author

I don't use it. An analog of std/bench has appeared.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment