Movatterモバイル変換


[0]ホーム

URL:


  1. scalene
  2. docs
Notebook
In [1]:
# An example program to profileimportnumpyasnpdeftest_me():foriinrange(6):x=np.array(range(10**7))y=np.array(np.random.uniform(0,100,size=(10**8)))
In [2]:
# Load Scalene%load_ext scalene
The scalene extension is already loaded. To reload it, use:  %reload_ext scalene
In [3]:
# Profile just one line of code%scruntest_me()
                                             [1]: % of time = 100.00% out of   6.02s.        ╷        ╷       ╷       ╷  LineTime––––––––––––Pythonnativesystem[1] ╺━━━━━━━┿━━━━━━━━┿━━━━━━━┿━━━━━━━┿━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╸     1│        │       │       │# An example program to profile     2│        │       │       │     3│        │       │       │import numpyas np     4│        │       │       │     5│        │       │       │def test_me():     6│        │       │       │for iinrange(6):     7    1%   35% │   7%  │        x= np.array(range(10**7))     8    2%   55% │       │        y= np.array(np.random.uniform(0,100, size=(10**8)))│        │       │       │                                                                                                 ╶───────┼────────┼───────┼───────┼────────────────────────────────────────────────────────────────────────────────────────────────╴│        │       │       │function summary for <ipython-input-14-3a53cdc5d2d5>     5    3%   91% │   6%  │test_me           ╵        ╵       ╵       ╵
In [4]:
# A full list of options%scrun--help
usage: scalene [-h] [--version] [--outfile OUTFILE] [--html]               [--reduced-profile] [--profile-interval PROFILE_INTERVAL]               [--cpu-only] [--profile-all] [--profile-only PROFILE_ONLY]               [--use-virtual-time]               [--cpu-percent-threshold CPU_PERCENT_THRESHOLD]               [--cpu-sampling-rate CPU_SAMPLING_RATE]               [--malloc-threshold MALLOC_THRESHOLD]Scalene: a high-precision CPU and memory profiler, version 1.3.2https://github.com/plasma-umass/scalenecommand-line:   % scalene [options] yourprogram.pyor   % python3 -m scalene [options] yourprogram.pyin Jupyter, line mode:   %scrun [options] statementin Jupyter, cell mode:   %%scalene [options]   code...   code...optional arguments:  -h, --help            show this help message and exit  --version             prints the version number for this release of Scalene and exits  --outfile OUTFILE     file to hold profiler output (default: stdout)  --html                output as HTML (default: text)  --reduced-profile     generate a reduced profile, with non-zero lines only (default: False)  --profile-interval PROFILE_INTERVAL                        output profiles every so many seconds (default: inf)  --cpu-only            only profile CPU time (default: profile CPU, memory, and copying)  --profile-all         profile all executed code, not just the target program (default: only the target program)  --profile-only PROFILE_ONLY                        profile only code in files matching the given strings, separated by commas (default: no restrictions)  --use-virtual-time    measure only CPU time, not time spent in I/O or blocking (default: False)  --cpu-percent-threshold CPU_PERCENT_THRESHOLD                        only report profiles with at least this percent of CPU time (default: 1%)  --cpu-sampling-rate CPU_SAMPLING_RATE                        CPU sampling rate (default: every 0.01s)  --malloc-threshold MALLOC_THRESHOLD                        only report profiles with at least this many allocations (default: 100)When running Scalene in the background, you can suspend/resume profilingfor the process ID that Scalene reports. For example:   % python3 -m scalene [options] yourprogram.py & Scalene now profiling process 12345   to suspend profiling: python3 -m scalene.profile --off --pid 12345   to resume profiling:  python3 -m scalene.profile --on  --pid 12345
In [5]:
# Generate a reduced profile (only lines with non-zero counts)%scrun--reduced-profiletest_me()
                                             [1]: % of time = 100.00% out of   6.67s.        ╷        ╷       ╷       ╷  LineTime––––––––––––Pythonnativesystem[1] ╺━━━━━━━┿━━━━━━━━┿━━━━━━━┿━━━━━━━┿━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╸   ...│        │       │       │     7│        │   34% │   7%  │        x= np.array(range(10**7))     8    2%   49% │   8%  │        y= np.array(np.random.uniform(0,100, size=(10**8)))│        │       │       │                                                                                                 ╶───────┼────────┼───────┼───────┼────────────────────────────────────────────────────────────────────────────────────────────────╴│        │       │       │function summary for <ipython-input-14-3a53cdc5d2d5>     5    2%   83% │  15%  │test_me           ╵        ╵       ╵       ╵
In [6]:
%%scalene --reduced-profile# Profile more than one line of code in a cellx = 0for i in range(1000):    for j in range(1000):        x += 1
         /var/folders/m7/sln1lr497jqcchb2ddh32rw00000gq/T/scalene_profile_qxy9xnh3.py: % of time = 100.00% out of   0.09s.        ╷        ╷       ╷       ╷  LineTime––––––––––––Pythonnativesystem/var/folders/m7/sln1lr497jqcchb2ddh32rw00000gq/T/scalene_profile_qxy9xnh3.py ╺━━━━━━━┿━━━━━━━━┿━━━━━━━┿━━━━━━━┿━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╸   ...│        │       │       │     4│   21%  │       │       │for jinrange(1000):     5   59%    6% │  13%  │        x+=1           ╵        ╵       ╵       ╵
In [ ]:

[8]ページ先頭

©2009-2025 Movatter.jp