Created
April 15, 2025 13:50
-
-
Save MrPandir/497bb713baa04f46a1304e7587c7493c to your computer and use it in GitHub Desktop.
Nushell performance measurement utility
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I don't use it. An analog of
std/bench
has appeared.