Created
October 22, 2018 16:29
-
-
Save prisae/af1b40ef4a2e16e130b39f6d7957be50 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# Test for FHT" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"from IPython.core import page\n", | |
"page.page = print\n", | |
"%load_ext memory_profiler\n", | |
"%load_ext line_profiler" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"Writing memtest.py\n" | |
] | |
} | |
], | |
"source": [ | |
"%%file memtest.py\n", | |
"\n", | |
"import numpy as np\n", | |
"\n", | |
"def pre_allocation(n):\n", | |
" out = np.zeros([n, n])\n", | |
" out[:, :] = np.arange(n*n).reshape(n, n)\n", | |
" return out\n", | |
"\n", | |
"def no_pre_allocation(n):\n", | |
" out = np.arange(n*n).reshape(n, n)\n", | |
" return out\n", | |
"\n", | |
"def overwriting(n):\n", | |
" out = np.zeros([n, n])\n", | |
" out = np.arange(n*n).reshape(n, n)\n", | |
" return out" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"Filename: /home/dtr/Codes/memtest.py\n", | |
"\n", | |
"Line # Mem usage Increment Line Contents\n", | |
"================================================\n", | |
" 4 52.9 MiB 52.9 MiB def pre_allocation(n):\n", | |
" 5 52.9 MiB 0.0 MiB out = np.zeros([n, n])\n", | |
" 6 815.8 MiB 762.9 MiB out[:, :] = np.arange(n*n).reshape(n, n)\n", | |
" 7 815.8 MiB 0.0 MiB return out\n", | |
"\n", | |
"Filename: /home/dtr/Codes/memtest.py\n", | |
"\n", | |
"Line # Mem usage Increment Line Contents\n", | |
"================================================\n", | |
" 9 52.9 MiB 52.9 MiB def no_pre_allocation(n):\n", | |
" 10 815.7 MiB 762.9 MiB out = np.arange(n*n).reshape(n, n)\n", | |
" 11 815.7 MiB 0.0 MiB return out\n", | |
"\n", | |
"Filename: /home/dtr/Codes/memtest.py\n", | |
"\n", | |
"Line # Mem usage Increment Line Contents\n", | |
"================================================\n", | |
" 13 52.9 MiB 52.9 MiB def overwriting(n):\n", | |
" 14 52.9 MiB 0.0 MiB out = np.zeros([n, n])\n", | |
" 15 815.8 MiB 762.9 MiB out = np.arange(n*n).reshape(n, n)\n", | |
" 16 815.8 MiB 0.0 MiB return out\n", | |
"\n", | |
"Timer unit: 1e-06 s\n", | |
"\n", | |
"Total time: 0.699112 s\n", | |
"File: /home/dtr/Codes/memtest.py\n", | |
"Function: pre_allocation at line 4\n", | |
"\n", | |
"Line # Hits Time Per Hit % Time Line Contents\n", | |
"==============================================================\n", | |
" 4 def pre_allocation(n):\n", | |
" 5 1 43.0 43.0 0.0 out = np.zeros([n, n])\n", | |
" 6 1 699067.0 699067.0 100.0 out[:, :] = np.arange(n*n).reshape(n, n)\n", | |
" 7 1 2.0 2.0 0.0 return out\n", | |
"Timer unit: 1e-06 s\n", | |
"\n", | |
"Total time: 0.344842 s\n", | |
"File: /home/dtr/Codes/memtest.py\n", | |
"Function: no_pre_allocation at line 9\n", | |
"\n", | |
"Line # Hits Time Per Hit % Time Line Contents\n", | |
"==============================================================\n", | |
" 9 def no_pre_allocation(n):\n", | |
" 10 1 344840.0 344840.0 100.0 out = np.arange(n*n).reshape(n, n)\n", | |
" 11 1 2.0 2.0 0.0 return out\n", | |
"Timer unit: 1e-06 s\n", | |
"\n", | |
"Total time: 0.346339 s\n", | |
"File: /home/dtr/Codes/memtest.py\n", | |
"Function: overwriting at line 13\n", | |
"\n", | |
"Line # Hits Time Per Hit % Time Line Contents\n", | |
"==============================================================\n", | |
" 13 def overwriting(n):\n", | |
" 14 1 114.0 114.0 0.0 out = np.zeros([n, n])\n", | |
" 15 1 346223.0 346223.0 100.0 out = np.arange(n*n).reshape(n, n)\n", | |
" 16 1 2.0 2.0 0.0 return out\n" | |
] | |
} | |
], | |
"source": [ | |
"from memtest import pre_allocation, no_pre_allocation, overwriting\n", | |
"\n", | |
"n=10000\n", | |
"\n", | |
"%mprun -f pre_allocation pre_allocation(n)\n", | |
"%mprun -f no_pre_allocation no_pre_allocation(n)\n", | |
"%mprun -f overwriting overwriting(n)\n", | |
"\n", | |
"%lprun -f pre_allocation pre_allocation(n)\n", | |
"%lprun -f no_pre_allocation no_pre_allocation(n)\n", | |
"%lprun -f overwriting overwriting(n)" | |
] | |
} | |
], | |
"metadata": { | |
"anaconda-cloud": {}, | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"name": "python3" | |
}, | |
"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.6.6" | |
}, | |
"nbpresent": { | |
"slides": { | |
"2a1825bf-35ff-4370-b129-ba51addc5c69": { | |
"id": "2a1825bf-35ff-4370-b129-ba51addc5c69", | |
"prev": "3d6a47d5-4fff-46fe-b063-1afce739efbb", | |
"regions": { | |
"c651f707-58e0-4b88-b861-0c6608fca1d5": { | |
"attrs": { | |
"height": 0.8, | |
"width": 0.8, | |
"x": 0.1, | |
"y": 0.1 | |
}, | |
"content": { | |
"cell": "6900d774-2898-4efd-9798-78bc8f08d0da", | |
"part": "whole" | |
}, | |
"id": "c651f707-58e0-4b88-b861-0c6608fca1d5" | |
} | |
} | |
}, | |
"3d6a47d5-4fff-46fe-b063-1afce739efbb": { | |
"id": "3d6a47d5-4fff-46fe-b063-1afce739efbb", | |
"prev": "aa9c2bcf-e54f-4714-946e-18921616a039", | |
"regions": { | |
"e461f359-4831-4693-84fe-480f6c1db14a": { | |
"attrs": { | |
"height": 0.8, | |
"width": 0.8, | |
"x": 0.1, | |
"y": 0.1 | |
}, | |
"content": { | |
"cell": "1a31a0e1-bcf6-452d-aabb-c48c94a9e85d", | |
"part": "whole" | |
}, | |
"id": "e461f359-4831-4693-84fe-480f6c1db14a" | |
} | |
} | |
}, | |
"54253e19-21cb-4738-94f0-109d6bbb2bde": { | |
"id": "54253e19-21cb-4738-94f0-109d6bbb2bde", | |
"prev": "5f5302d2-4747-4c5a-a6c3-1d0fc8f7fb66", | |
"regions": { | |
"1735c9df-b5c2-40d7-b562-b869e4b966cd": { | |
"attrs": { | |
"height": 0.8, | |
"width": 0.8, | |
"x": 0.1, | |
"y": 0.1 | |
}, | |
"content": { | |
"cell": "f85d2094-6d09-4627-a0ab-7cab37ed3c9f", | |
"part": "whole" | |
}, | |
"id": "1735c9df-b5c2-40d7-b562-b869e4b966cd" | |
} | |
} | |
}, | |
"5f5302d2-4747-4c5a-a6c3-1d0fc8f7fb66": { | |
"id": "5f5302d2-4747-4c5a-a6c3-1d0fc8f7fb66", | |
"prev": "fc333044-619d-44bd-8c7f-0a53dd4b220a", | |
"regions": { | |
"41618366-0a77-4f2d-9d9b-77ed062d6959": { | |
"attrs": { | |
"height": 0.8, | |
"width": 0.8, | |
"x": 0.1, | |
"y": 0.1 | |
}, | |
"content": { | |
"cell": "83e23522-1665-45d6-8bc0-869b981a0e66", | |
"part": "whole" | |
}, | |
"id": "41618366-0a77-4f2d-9d9b-77ed062d6959" | |
} | |
} | |
}, | |
"aa9c2bcf-e54f-4714-946e-18921616a039": { | |
"id": "aa9c2bcf-e54f-4714-946e-18921616a039", | |
"prev": "54253e19-21cb-4738-94f0-109d6bbb2bde", | |
"regions": { | |
"1b48f280-81c6-4746-8fff-091d4b10b448": { | |
"attrs": { | |
"height": 0.8, | |
"width": 0.8, | |
"x": 0.1, | |
"y": 0.1 | |
}, | |
"content": { | |
"cell": "0631a68b-7d4d-4326-abff-8628f2004afc", | |
"part": "whole" | |
}, | |
"id": "1b48f280-81c6-4746-8fff-091d4b10b448" | |
} | |
} | |
}, | |
"b5a49768-441a-449c-bbf3-d2a7febf0235": { | |
"id": "b5a49768-441a-449c-bbf3-d2a7febf0235", | |
"prev": null, | |
"regions": { | |
"7ae15b0a-8675-4544-8708-f2e95dda286f": { | |
"attrs": { | |
"height": 0.8, | |
"width": 0.8, | |
"x": 0.1, | |
"y": 0.1 | |
}, | |
"content": { | |
"cell": "4cf9c8a2-cf5f-45cd-b5da-0b1c7fe23108", | |
"part": "whole" | |
}, | |
"id": "7ae15b0a-8675-4544-8708-f2e95dda286f" | |
} | |
} | |
}, | |
"bc930404-89e7-4fc9-a1f9-e9edc1f4d1d4": { | |
"id": "bc930404-89e7-4fc9-a1f9-e9edc1f4d1d4", | |
"prev": "2a1825bf-35ff-4370-b129-ba51addc5c69", | |
"regions": { | |
"76296bab-9070-4528-b79c-558debc8f675": { | |
"attrs": { | |
"height": 0.8, | |
"width": 0.8, | |
"x": 0.1, | |
"y": 0.1 | |
}, | |
"content": { | |
"cell": "3ac01b43-1f53-4902-a857-5a0b0a6ef59b", | |
"part": "whole" | |
}, | |
"id": "76296bab-9070-4528-b79c-558debc8f675" | |
} | |
} | |
}, | |
"fc333044-619d-44bd-8c7f-0a53dd4b220a": { | |
"id": "fc333044-619d-44bd-8c7f-0a53dd4b220a", | |
"prev": "b5a49768-441a-449c-bbf3-d2a7febf0235", | |
"regions": { | |
"fea6658a-c555-450d-b33b-0e44fe7b1cf8": { | |
"attrs": { | |
"height": 0.8, | |
"width": 0.8, | |
"x": 0.1, | |
"y": 0.1 | |
}, | |
"content": { | |
"cell": "d0a7e487-d7b9-418c-810f-f12d33c88c85", | |
"part": "whole" | |
}, | |
"id": "fea6658a-c555-450d-b33b-0e44fe7b1cf8" | |
} | |
} | |
} | |
}, | |
"themes": {} | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 1 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment