Understand profme
Module#
Author: Zakariya Abugrin | Date: May 2025
Introduction#
This tutorial shows how to use profme
from utils
module.
Import reservoirflow
#
We start with importing reservoirflow
as rf
. The abbreviation rf
refers to reservoirflow
where all modules under this library can be accessed. rf
is also used throughout the API documentation. We recommend our users to stick with this convention.
1import reservoirflow as rf
2
3print(rf.__version__)
0.1.0b3
1@rf.utils.profme.timeit
2def sum_numbers(n):
3 sum = 0
4 for a in range(n):
5 sum += a
6 return sum
7
8sum_numbers(100000)
func:'sum_numbers' took: 0.0036 sec
4999950000
1@rf.utils.profme.lProfiler(print_output=True, save_output=False)
2def sum_numbers(n):
3 sum = 0
4 for a in range(n):
5 sum += a
6 return sum
7
8sum_numbers(100000)
Timer unit: 1e-09 s
Total time: 0.0255886 s
File: /tmp/ipykernel_3129/545659262.py
Function: sum_numbers at line 1
Line # Hits Time Per Hit % Time Line Contents
==============================================================
1 @rf.utils.profme.lProfiler(print_output=True, save_output=False)
2 def sum_numbers(n):
3 1 691.0 691.0 0.0 sum = 0
4 100001 11905079.0 119.0 46.5 for a in range(n):
5 100000 13682587.0 136.8 53.5 sum += a
6 1 240.0 240.0 0.0 return sum
4999950000
1@rf.utils.profme.cProfiler()
2def sum_numbers(n):
3 sum = 0
4 for a in range(n):
5 sum = add(sum,a)
6 return sum
7def add(sum, a):
8 return sum+a
9
10
11sum_numbers(100000)
ncalls tottime percall cumtime percall.1 \
0 1 0.018 0.018 0.026 0.026
1 100000 0.008 0.000 0.008 0.000
2 1 0.000 0.000 0.000 0.000
filename:lineno(function)
0 /tmp/ipykernel_3129/568536641.py:1(sum_numbers)
1 /tmp/ipykernel_3129/568536641.py:7(add)
2 {method 'disable' of '_lsprof.Profiler' objects}
4999950000
Comments ๐ฌ#
Feel free to make a comment, ask a question, or share your opinion about this specific content. Please keep in mind the Commenting Guidelines โ.