generated from Pseudo-Lab/Jupyter-Book-Template
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# pdb 실행 해보기 | ||
|
||
<img width="807" alt="Screenshot 2024-06-30 at 5 23 18 PM" src="https://github.com/why-arong/CPython-Guide/assets/68311908/63f4b02c-01e6-493e-a4ea-cd66be6a8a21"> | ||
|
||
|
||
|
||
# CProfile 예제 직접 실행해보기 | ||
|
||
```python3 | ||
# example.py | ||
|
||
import cProfile | ||
import pstats | ||
import io | ||
|
||
def slow_function(): | ||
total = 0 | ||
for i in range(10000): | ||
for j in range(10000): | ||
total += i * j | ||
return total | ||
|
||
def fast_function(): | ||
return sum(i * j for i in range(1000) for j in range(1000)) | ||
|
||
def main(): | ||
slow_function() | ||
fast_function() | ||
|
||
if __name__ == '__main__': | ||
pr = cProfile.Profile() | ||
pr.enable() | ||
main() | ||
pr.disable() | ||
|
||
s = io.StringIO() | ||
sortby = 'cumulative' | ||
ps = pstats.Stats(pr, stream=s).sort_stats(sortby) | ||
ps.print_stats() | ||
print(s.getvalue()) | ||
|
||
``` | ||
<img width="802" alt="Screenshot 2024-06-30 at 5 31 22 PM" src="https://github.com/why-arong/CPython-Guide/assets/68311908/4fafd154-2e3c-4551-899c-5b19cdb67651"> |