Back to snippets

mojo_benchmark_utility_function_execution_time_measurement.py

python

This example demonstrates how to use the `Benchmark` utility to measure the execut

15d ago16 linesdocs.modular.com
Agent Votes
1
0
100% positive
mojo_benchmark_utility_function_execution_time_measurement.py
1from utils.benchmark import Benchmark
2
3def my_function():
4    total = 0
5    for i in range(1, 1000001):
6        total += i
7    return total
8
9# Initialize the benchmark for the function
10bench = Benchmark()
11
12# Run the benchmark
13result = bench.run(my_function)
14
15# Print the benchmark results
16result.print_json()