{ "metadata": { "name": "", "signature": "sha256:88504b4d485d303c7bbcbfd224e1fe5be1041b166eed33c9a46f91730c6396b0" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "[Sebastian Raschka](http://sebastianraschka.com) \n", "last updated: 10/10/2014\n", "\n", "### PyPrind 2.6.2 demo" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", "I would be happy to hear your comments and suggestions. \n", "Please feel free to drop me a note via\n", "[twitter](https://twitter.com/rasbt), [email](mailto:bluewoodtree@gmail.com), or [google+](https://plus.google.com/118404394130788869227).\n", "
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Sections" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "- [Basic Progress Bar](#bar_basic) \n", "- [Basic Percentage Indicator](#percent_basic) \n", "- [Progress Bar/Percentage Indicator - Reporting tracking information](#info)\n", "- [Progress Bar/Percentage Indicator - Reporting CPU and memory usage](#percent_cpu) \n", "- [Progress Bar/Percentage Indicator - Setting a title](#title)\n", "- [Progress Bar - Changing the default width](#width)\n", "- [Progress Bar/Percentage Indicator - Changing the output stream](#streams)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", "
" ] }, { "cell_type": "code", "collapsed": false, "input": [ "import pyprind" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "
\n", "
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Basic Progress Bar" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "[[back to section overview](#sections)]" ] }, { "cell_type": "code", "collapsed": false, "input": [ "n = 150000\n", "\n", "bar = pyprind.ProgBar(n)\n", "for i in range(n):\n", " # do some computation\n", " bar.update()" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "
\n", "
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "## Basic Percentage Indicator" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "[[back to section overview](#sections)]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "*Note: the Percentage indicator is significantly slower due to background computation. \n", "Thus, it is recommended for tasks with less iterations but longer computational time per iteration.*" ] }, { "cell_type": "code", "collapsed": false, "input": [ "n = 1500\n", "\n", "perc = pyprind.ProgPercent(n)\n", "for i in range(n):\n", " # do some computation\n", " perc.update()" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "
\n", "
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Progress Bar/Percentage Indicator - Reporting tracking information" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Simply `print()` the tracking object after the tracking has completed." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "[[back to section overview](#sections)]" ] }, { "cell_type": "code", "collapsed": false, "input": [ "n = 150000\n", "\n", "bar = pyprind.ProgBar(n)\n", "for i in range(n):\n", " # do some computation\n", " bar.update()\n", "print(bar)" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "n = 150000\n", "\n", "bar = pyprind.ProgBar(n, monitor=True, title='Job_1')\n", "for i in range(n):\n", " # do some computation\n", " bar.update()\n", " \n", "# print report for future reference\n", "print(bar)" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", "
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "## Progress Bar/Percentage Indicator - Reporting CPU and memory usage" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "[[back to section overview](#sections)]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "`monitor` (`bool`): default False. Monitors CPU and memory usage if True \n", " (requires 'psutil' package)." ] }, { "cell_type": "code", "collapsed": false, "input": [ "n = 150000\n", "\n", "bar = pyprind.ProgBar(n, monitor=True)\n", "for i in range(n):\n", " # do some computation\n", " bar.update()\n", "print(bar)" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "" ] }, { "cell_type": "code", "collapsed": false, "input": [ "n = 1500\n", "\n", "perc = pyprind.ProgPercent(n, monitor=True)\n", "for i in range(n):\n", " # do some computation\n", " perc.update()\n", "print(perc)" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "
\n", "
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Progress Bar/Percentage Indicator - Setting a title" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "[[back to section overview](#sections)]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "`title` (`str`): default ''. A title for the progress bar" ] }, { "cell_type": "code", "collapsed": false, "input": [ "n = 150000\n", "\n", "bar = pyprind.ProgBar(n, title='My 1st Progress Bar')\n", "for i in range(n):\n", " # do some computation\n", " bar.update()" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "n = 1500\n", "\n", "perc = pyprind.ProgPercent(n, title='My 1st Percent Tracker')\n", "for i in range(n):\n", " # do some computation\n", " perc.update()" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "
\n", "
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Progress Bar - Changing the default width" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "[[back to section overview](#sections)]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "`width` (`int`): default 30. Sets the progress bar width in characters." ] }, { "cell_type": "code", "collapsed": false, "input": [ "n = 150000\n", "\n", "bar = pyprind.ProgBar(n, width=10)\n", "for i in range(n):\n", " # do some computation\n", " bar.update()\n", "\n", "bar = pyprind.ProgBar(n, width=70)\n", "for i in range(n):\n", " # do some computation\n", " bar.update()" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "
\n", "
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Progress Bar/Percentage Indicator - Changing the output stream" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "`stream` (`int`): default 2. Takes 1 for stdout, 2 for stderr, or given stream object" ] }, { "cell_type": "code", "collapsed": false, "input": [ "n = 150000\n", "\n", "bar = pyprind.ProgBar(n, stream=1)\n", "for i in range(n):\n", " # do some computation\n", " bar.update()" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "bar = pyprind.ProgBar(n, stream=2)\n", "for i in range(n):\n", " # do some computation\n", " bar.update()" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "import sys\n", "\n", "bar = pyprind.ProgBar(n, stream=sys.stdout)\n", "for i in range(n):\n", " # do some computation\n", " bar.update()" ], "language": "python", "metadata": {}, "outputs": [] } ], "metadata": {} } ] }