preveen-stack / nodejs

0 stars 0 forks source link

using pyinstrument #19

Open preveen-stack opened 6 months ago

preveen-stack commented 6 months ago
# Example script to profile using PyInstrument
import pyinstrument

def fibonacci(n):
    if n <= 1:
        return n
    else:
        return fibonacci(n-1) + fibonacci(n-2)

def main():
    with pyinstrument.Profiler() as profiler:
        # Code to be profiled
        result = fibonacci(30)

    print(profiler.output_text(unicode=True, color=True))

if __name__ == "__main__":
    main()
preveen-stack commented 6 months ago

  _     ._   __/__   _ _  _  _ _/_   Recorded: 13:51:19  Samples:  805
 /_//_/// /_\ / //_// / //_'/ //     Duration: 0.805     CPU time: 0.802
/   _/                      v4.6.2

Program: ex-pyinstrument.py

0.805 main  ex-pyinstrument.py:10
└─ 0.805 fibonacci  ex-pyinstrument.py:4
   └─ 0.805 fibonacci  ex-pyinstrument.py:4
      └─ 0.805 fibonacci  ex-pyinstrument.py:4
         └─ 0.805 fibonacci  ex-pyinstrument.py:4
            └─ 0.805 fibonacci  ex-pyinstrument.py:4
               └─ 0.805 fibonacci  ex-pyinstrument.py:4
                  └─ 0.805 fibonacci  ex-pyinstrument.py:4
                     └─ 0.805 fibonacci  ex-pyinstrument.py:4
                        └─ 0.805 fibonacci  ex-pyinstrument.py:4
                           └─ 0.805 fibonacci  ex-pyinstrument.py:4
                              └─ 0.805 fibonacci  ex-pyinstrument.py:4
                                 └─ 0.805 fibonacci  ex-pyinstrument.py:4
                                    └─ 0.804 fibonacci  ex-pyinstrument.py:4
                                       └─ 0.803 fibonacci  ex-pyinstrument.py:4
                                          └─ 0.801 fibonacci  ex-pyinstrument.py:4
                                             ├─ 0.788 fibonacci  ex-pyinstrument.py:4
                                             │  ├─ 0.770 fibonacci  ex-pyinstrument.py:4
                                             │  │  ├─ 0.741 fibonacci  ex-pyinstrument.py:4
                                             │  │  │  ├─ 0.687 fibonacci  ex-pyinstrument.py:4
                                             │  │  │  │  ├─ 0.583 fibonacci  ex-pyinstrument.py:4
                                             │  │  │  │  │  ├─ 0.455 fibonacci  ex-pyinstrument.py:4
                                             │  │  │  │  │  │  ├─ 0.291 fibonacci  ex-pyinstrument.py:4
                                             │  │  │  │  │  │  │  ├─ 0.160 fibonacci  ex-pyinstrument.py:4
                                             │  │  │  │  │  │  │  │  ├─ 0.099 [self]  ex-pyinstrument.py
                                             │  │  │  │  │  │  │  │  └─ 0.061 fibonacci  ex-pyinstrument.py:4
                                             │  │  │  │  │  │  │  │     ├─ 0.043 [self]  ex-pyinstrument.py
                                             │  │  │  │  │  │  │  │     └─ 0.018 fibonacci  ex-pyinstrument.py:4
                                             │  │  │  │  │  │  │  │        └─ 0.016 [self]  ex-pyinstrument.py
                                             │  │  │  │  │  │  │  └─ 0.131 [self]  ex-pyinstrument.py
                                             │  │  │  │  │  │  └─ 0.164 [self]  ex-pyinstrument.py
                                             │  │  │  │  │  └─ 0.128 [self]  ex-pyinstrument.py
                                             │  │  │  │  └─ 0.104 [self]  ex-pyinstrument.py
                                             │  │  │  └─ 0.054 [self]  ex-pyinstrument.py
                                             │  │  └─ 0.029 [self]  ex-pyinstrument.py
                                             │  └─ 0.018 [self]  ex-pyinstrument.py
                                             └─ 0.013 [self]  ex-pyinstrument.py