Skip to content

Instantly share code, notes, and snippets.

@vinothpandian
Created November 9, 2021 08:24
Show Gist options
  • Save vinothpandian/01403012b89ffcfcf6d43a232c0b1735 to your computer and use it in GitHub Desktop.
Save vinothpandian/01403012b89ffcfcf6d43a232c0b1735 to your computer and use it in GitHub Desktop.
profiler_test.ipynb
Display the source blob
Display the rendered blob
Raw
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "profiler_test.ipynb",
"private_outputs": true,
"provenance": [],
"collapsed_sections": [],
"authorship_tag": "ABX9TyMteLeP2LVeEOSTsw2E+7Yv",
"include_colab_link": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
}
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/gist/vinothpandian/01403012b89ffcfcf6d43a232c0b1735/profiler_test.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "code",
"metadata": {
"id": "WLdQkr8KQLuP"
},
"source": [
"!pip install -q memory_profiler line_profiler"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "GTHlbR3wQKFQ"
},
"source": [
"%load_ext memory_profiler\n",
"%load_ext line_profiler"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "FcBAiWxhOcRw"
},
"source": [
"%%file demo.py\n",
"\n",
"def imperative_pad(n):\n",
" arr = [0]\n",
" for i in range(1, n):\n",
" arr.insert(0, i)\n",
" arr.append(i)\n",
" return arr\n",
"\n",
"def declarative_pad(n):\n",
" arr = [0]\n",
" for i in range(1, n):\n",
" arr = [i, *arr, i]\n",
" return arr"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "zw_wjd31x2VT"
},
"source": [
"from demo import imperative_pad, declarative_pad"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "XH0bGXEVOs6K"
},
"source": [
"%timeit imperative_pad(10000)"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "gHR81uwbPFUN"
},
"source": [
"%timeit declarative_pad(10000)"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "TQ35QowhPp73"
},
"source": [
"%prun imperative_pad(1000)"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "IfIRk9-VP2bU"
},
"source": [
"%prun declarative_pad(1000)"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "bnww_W83QYqd"
},
"source": [
"%lprun -f imperative_pad imperative_pad(1000)"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "c-XN7M9uQYqe"
},
"source": [
"%lprun -f declarative_pad declarative_pad(1000)"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "DytOvibbQfaG"
},
"source": [
""
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "gpx_eJDrRDgl"
},
"source": [
"%memit imperative_pad(1000)"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "nq8zScMERDgm"
},
"source": [
"%memit declarative_pad(1000)"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "NKnzzvgRRKQ0"
},
"source": [
""
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "FEXWpj0yRS_B"
},
"source": [
"%mprun -f imperative_pad imperative_pad(1000)"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "tp4rJL52RS_B"
},
"source": [
"%mprun -f declarative_pad declarative_pad(1000)"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "m3gGeyeRRZBu"
},
"source": [
""
],
"execution_count": null,
"outputs": []
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment