{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# scalene\n", "\n", "scalene creates profiles for CPU and memory very quickly. The overhead is usually very low at 10–20%.\n", "\n", "
usage: scalene run [-h] [-o OUTFILE] [--cpu-only] [-c CONFIG_FILE]\n", " [--help-advanced]\n", "\n", "Profile a Python program with Scalene.\n", "\n", "examples:\n", " % scalene run prog.py # profile, save to scalene-profile.json\n", " % scalene run -o my.json prog.py # save to custom file\n", " % scalene run --cpu-only prog.py # profile CPU only (faster)\n", " % scalene run -c scalene.yaml prog.py # load options from config file\n", " % scalene run prog.py --- --arg # pass args to program\n", " % scalene run --help-advanced # show advanced options\n", "\n", "options:\n", " -h, --help show this help message and exit\n", " -o, --outfile OUTFILE\n", " output file (default: scalene-profile.json)\n", " --cpu-only only profile CPU time (no memory/GPU)\n", " -c, --config CONFIG_FILE\n", " load options from YAML config file\n", " --help-advanced show advanced options\n", "\n", "\n" ], "text/plain": [ "\u001b[1;34musage:\u001b[0m \u001b[1;35mscalene\u001b[0m run [-h] [-o OUTFILE] [--cpu-only] [-c CONFIG_FILE]\n", " [--help-advanced]\n", "\n", "Profile a Python program with Scalene.\n", "\n", "examples:\n", " % scalene run prog.py # profile, save to scalene-profile.json\n", " % scalene run -o my.json prog.py # save to custom file\n", " % scalene run --cpu-only prog.py # profile CPU only (faster)\n", " % scalene run -c scalene.yaml prog.py # load options from config file\n", " % scalene run prog.py --- --arg # pass args to program\n", " % scalene run --help-advanced # show advanced options\n", "\n", "\u001b[1;34moptions:\u001b[0m\n", " \u001b[1;32m-h\u001b[0m, \u001b[1;36m--help\u001b[0m show this help message and exit\n", " \u001b[1;32m-o\u001b[0m, \u001b[1;36m--outfile\u001b[0m \u001b[1;33mOUTFILE\u001b[0m\n", " output file (default: scalene-profile.json)\n", " \u001b[1;36m--cpu-only\u001b[0m only profile CPU time (no memory/GPU)\n", " \u001b[1;32m-c\u001b[0m, \u001b[1;36m--config\u001b[0m \u001b[1;33mCONFIG_FILE\u001b[0m\n", " load options from YAML config file\n", " \u001b[1;36m--help-advanced\u001b[0m show advanced options\n", "\n" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%scrun --help" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Profile with more than one line of code in a cell" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.status.busy": "2026-05-18T17:04:53.769564Z", "iopub.status.idle": "2026-05-18T17:04:53.770073Z", "shell.execute_reply": "2026-05-18T17:04:53.769871Z", "shell.execute_reply.started": "2026-05-18T17:04:53.769838Z" } }, "outputs": [], "source": [ "%%scalene --reduced-profile\n", "x = 0\n", "for _i in range(1000):\n", " for _j in range(1000):\n", " x += 1" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3.13 Kernel", "language": "python", "name": "python313" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.13.0" }, "latex_envs": { "LaTeX_envs_menu_present": true, "autoclose": false, "autocomplete": true, "bibliofile": "biblio.bib", "cite_by": "apalike", "current_citInitial": 1, "eqLabelWithNumbers": true, "eqNumInitial": 1, "hotkeys": { "equation": "Ctrl-E", "itemize": "Ctrl-I" }, "labels_anchors": false, "latex_user_defs": false, "report_style_numbering": false, "user_envs_cfg": false }, "varInspector": { "cols": { "lenName": 16, "lenType": 16, "lenVar": 40 }, "kernels_config": { "python": { "delete_cmd_postfix": "", "delete_cmd_prefix": "del ", "library": "var_list.py", "varRefreshCmd": "print(var_dic_list())" }, "r": { "delete_cmd_postfix": ") ", "delete_cmd_prefix": "rm(", "library": "var_list.r", "varRefreshCmd": "cat(var_dic_list()) " } }, "types_to_exclude": [ "module", "function", "builtin_function_or_method", "instance", "_Feature" ], "window_display": false }, "widgets": { "application/vnd.jupyter.widget-state+json": { "state": {}, "version_major": 2, "version_minor": 0 } } }, "nbformat": 4, "nbformat_minor": 4 }