Skip to content

Commit eb35644

Browse files
committed
numpy test
1 parent 191ff49 commit eb35644

File tree

2 files changed

+226
-4
lines changed

2 files changed

+226
-4
lines changed

.ipynb_checkpoints/timeit_tests-checkpoint.ipynb

Lines changed: 113 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"metadata": {
33
"name": "",
4-
"signature": "sha256:ab74fdc9e8ae58388d1fc428599abc86a3d03938d0f51769cef38ab4028d516a"
4+
"signature": "sha256:d5895f75b2ac58db150d7b521682366a447ffb2fb0b7db7e551edd40e6d1ab10"
55
},
66
"nbformat": 3,
77
"nbformat_minor": 0,
@@ -66,7 +66,8 @@
6666
" - [Adding elements to a dictionary](#adding_dict_elements)\n",
6767
"- [Comprehensions vs. for-loops](#comprehensions)\n",
6868
"- [Copying files by searching directory trees](#find_copy)\n",
69-
"- [Returning column vectors slicing through a numpy array](#row_vectors)"
69+
"- [Returning column vectors slicing through a numpy array](#row_vectors)\n",
70+
"- [Speed of numpy functions vs Python built-ins and std. lib.](#numpy)"
7071
]
7172
},
7273
{
@@ -1691,6 +1692,116 @@
16911692
],
16921693
"prompt_number": 91
16931694
},
1695+
{
1696+
"cell_type": "markdown",
1697+
"metadata": {},
1698+
"source": [
1699+
"<a name='numpy'></a>\n",
1700+
"<br>\n",
1701+
"<br>\n"
1702+
]
1703+
},
1704+
{
1705+
"cell_type": "markdown",
1706+
"metadata": {},
1707+
"source": [
1708+
"# Speed of numpy functions vs Python built-ins and std. lib."
1709+
]
1710+
},
1711+
{
1712+
"cell_type": "code",
1713+
"collapsed": false,
1714+
"input": [
1715+
"import numpy as np\n",
1716+
"import timeit\n",
1717+
"\n",
1718+
"samples = list(range(1000000))\n",
1719+
"\n",
1720+
"%timeit(sum(samples))\n",
1721+
"%timeit(np.sum(samples))"
1722+
],
1723+
"language": "python",
1724+
"metadata": {},
1725+
"outputs": [
1726+
{
1727+
"output_type": "stream",
1728+
"stream": "stdout",
1729+
"text": [
1730+
"100 loops, best of 3: 18.3 ms per loop\n",
1731+
"10 loops, best of 3: 136 ms per loop"
1732+
]
1733+
},
1734+
{
1735+
"output_type": "stream",
1736+
"stream": "stdout",
1737+
"text": [
1738+
"\n"
1739+
]
1740+
}
1741+
],
1742+
"prompt_number": 6
1743+
},
1744+
{
1745+
"cell_type": "code",
1746+
"collapsed": false,
1747+
"input": [
1748+
"%timeit(list(range(1000000)))\n",
1749+
"%timeit(np.arange(1000000))\n",
1750+
"\n",
1751+
"# note that in Python range() is implemented as xrange()\n",
1752+
"# with lazy evaluation (generator)"
1753+
],
1754+
"language": "python",
1755+
"metadata": {},
1756+
"outputs": [
1757+
{
1758+
"output_type": "stream",
1759+
"stream": "stdout",
1760+
"text": [
1761+
"10 loops, best of 3: 82.6 ms per loop\n",
1762+
"100 loops, best of 3: 5.35 ms per loop"
1763+
]
1764+
},
1765+
{
1766+
"output_type": "stream",
1767+
"stream": "stdout",
1768+
"text": [
1769+
"\n"
1770+
]
1771+
}
1772+
],
1773+
"prompt_number": 11
1774+
},
1775+
{
1776+
"cell_type": "code",
1777+
"collapsed": false,
1778+
"input": [
1779+
"import statistics\n",
1780+
"\n",
1781+
"%timeit(statistics.mean(samples))\n",
1782+
"%timeit(np.mean(samples))"
1783+
],
1784+
"language": "python",
1785+
"metadata": {},
1786+
"outputs": [
1787+
{
1788+
"output_type": "stream",
1789+
"stream": "stdout",
1790+
"text": [
1791+
"1 loops, best of 3: 1.14 s per loop\n",
1792+
"10 loops, best of 3: 141 ms per loop"
1793+
]
1794+
},
1795+
{
1796+
"output_type": "stream",
1797+
"stream": "stdout",
1798+
"text": [
1799+
"\n"
1800+
]
1801+
}
1802+
],
1803+
"prompt_number": 14
1804+
},
16941805
{
16951806
"cell_type": "code",
16961807
"collapsed": false,

benchmarks/timeit_tests.ipynb

Lines changed: 113 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"metadata": {
33
"name": "",
4-
"signature": "sha256:ab74fdc9e8ae58388d1fc428599abc86a3d03938d0f51769cef38ab4028d516a"
4+
"signature": "sha256:d5895f75b2ac58db150d7b521682366a447ffb2fb0b7db7e551edd40e6d1ab10"
55
},
66
"nbformat": 3,
77
"nbformat_minor": 0,
@@ -66,7 +66,8 @@
6666
" - [Adding elements to a dictionary](#adding_dict_elements)\n",
6767
"- [Comprehensions vs. for-loops](#comprehensions)\n",
6868
"- [Copying files by searching directory trees](#find_copy)\n",
69-
"- [Returning column vectors slicing through a numpy array](#row_vectors)"
69+
"- [Returning column vectors slicing through a numpy array](#row_vectors)\n",
70+
"- [Speed of numpy functions vs Python built-ins and std. lib.](#numpy)"
7071
]
7172
},
7273
{
@@ -1691,6 +1692,116 @@
16911692
],
16921693
"prompt_number": 91
16931694
},
1695+
{
1696+
"cell_type": "markdown",
1697+
"metadata": {},
1698+
"source": [
1699+
"<a name='numpy'></a>\n",
1700+
"<br>\n",
1701+
"<br>\n"
1702+
]
1703+
},
1704+
{
1705+
"cell_type": "markdown",
1706+
"metadata": {},
1707+
"source": [
1708+
"# Speed of numpy functions vs Python built-ins and std. lib."
1709+
]
1710+
},
1711+
{
1712+
"cell_type": "code",
1713+
"collapsed": false,
1714+
"input": [
1715+
"import numpy as np\n",
1716+
"import timeit\n",
1717+
"\n",
1718+
"samples = list(range(1000000))\n",
1719+
"\n",
1720+
"%timeit(sum(samples))\n",
1721+
"%timeit(np.sum(samples))"
1722+
],
1723+
"language": "python",
1724+
"metadata": {},
1725+
"outputs": [
1726+
{
1727+
"output_type": "stream",
1728+
"stream": "stdout",
1729+
"text": [
1730+
"100 loops, best of 3: 18.3 ms per loop\n",
1731+
"10 loops, best of 3: 136 ms per loop"
1732+
]
1733+
},
1734+
{
1735+
"output_type": "stream",
1736+
"stream": "stdout",
1737+
"text": [
1738+
"\n"
1739+
]
1740+
}
1741+
],
1742+
"prompt_number": 6
1743+
},
1744+
{
1745+
"cell_type": "code",
1746+
"collapsed": false,
1747+
"input": [
1748+
"%timeit(list(range(1000000)))\n",
1749+
"%timeit(np.arange(1000000))\n",
1750+
"\n",
1751+
"# note that in Python range() is implemented as xrange()\n",
1752+
"# with lazy evaluation (generator)"
1753+
],
1754+
"language": "python",
1755+
"metadata": {},
1756+
"outputs": [
1757+
{
1758+
"output_type": "stream",
1759+
"stream": "stdout",
1760+
"text": [
1761+
"10 loops, best of 3: 82.6 ms per loop\n",
1762+
"100 loops, best of 3: 5.35 ms per loop"
1763+
]
1764+
},
1765+
{
1766+
"output_type": "stream",
1767+
"stream": "stdout",
1768+
"text": [
1769+
"\n"
1770+
]
1771+
}
1772+
],
1773+
"prompt_number": 11
1774+
},
1775+
{
1776+
"cell_type": "code",
1777+
"collapsed": false,
1778+
"input": [
1779+
"import statistics\n",
1780+
"\n",
1781+
"%timeit(statistics.mean(samples))\n",
1782+
"%timeit(np.mean(samples))"
1783+
],
1784+
"language": "python",
1785+
"metadata": {},
1786+
"outputs": [
1787+
{
1788+
"output_type": "stream",
1789+
"stream": "stdout",
1790+
"text": [
1791+
"1 loops, best of 3: 1.14 s per loop\n",
1792+
"10 loops, best of 3: 141 ms per loop"
1793+
]
1794+
},
1795+
{
1796+
"output_type": "stream",
1797+
"stream": "stdout",
1798+
"text": [
1799+
"\n"
1800+
]
1801+
}
1802+
],
1803+
"prompt_number": 14
1804+
},
16941805
{
16951806
"cell_type": "code",
16961807
"collapsed": false,

0 commit comments

Comments
 (0)