Skip to content

Instantly share code, notes, and snippets.

@travishen
Created August 17, 2018 18:26
Show Gist options
  • Save travishen/7ead7f7588208fa4971498fac6dd13b4 to your computer and use it in GitHub Desktop.
Save travishen/7ead7f7588208fa4971498fac6dd13b4 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 32,
"metadata": {},
"outputs": [],
"source": [
"import sys"
]
},
{
"cell_type": "code",
"execution_count": 33,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0 require: 24 bytes\n"
]
}
],
"source": [
"print('0 require: ' + str(sys.getsizeof(0)) + ' bytes')"
]
},
{
"cell_type": "code",
"execution_count": 34,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1 require: 28 bytes\n"
]
}
],
"source": [
"print('1 require: ' + str(sys.getsizeof(1)) + ' bytes')"
]
},
{
"cell_type": "code",
"execution_count": 35,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"2 ** 1000 require: 160 bytes\n",
"also means 1088 bits\n"
]
}
],
"source": [
"print('2 ** 1000 require: ' + str(sys.getsizeof(2**1000)) + ' bytes')\n",
"print('also means %s bits' % ((160 - 24) * 8)) # overhead of 24 bytes"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"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.5.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment