diff --git a/tutorials/key_differences_between_python_2_and_3.html b/tutorials/key_differences_between_python_2_and_3.html index a839b1a..c8b8cbe 100644 --- a/tutorials/key_differences_between_python_2_and_3.html +++ b/tutorials/key_differences_between_python_2_and_3.html @@ -2862,6 +2862,100 @@ In [8]: + +
+
+
+
+
+

Note
Some people pointed out the speed difference between Python 3's range() and Python2's xrange(). Since they are implemented the same way one would expect the same speed. However the difference here just comes from the fact that Python 3 generally tends to run slower than Python 2.

+
+
+
+
+
+
+In [3]: +
+
+
+
def test_while():
+    i = 0
+    while i < 20000:
+        i += 1
+    return
+
+ +
+
+
+ +
+
+
+
+In [4]: +
+
+
+
print('Python', python_version())
+%timeit test_while()
+
+ +
+
+
+ +
+
+ + +
+
+
+Python 3.4.1
+100 loops, best of 3: 2.68 ms per loop
+
+
+
+
+ +
+
+ +
+
+
+
+In [6]: +
+
+
+
print 'Python', python_version()
+%timeit test_while()
+
+ +
+
+
+ +
+
+ + +
+
+
+Python 2.7.6
+1000 loops, best of 3: 1.72 ms per loop
+
+
+
+
+ +
+
+
diff --git a/tutorials/key_differences_between_python_2_and_3.ipynb b/tutorials/key_differences_between_python_2_and_3.ipynb index ac07efa..79065ea 100644 --- a/tutorials/key_differences_between_python_2_and_3.ipynb +++ b/tutorials/key_differences_between_python_2_and_3.ipynb @@ -1,7 +1,7 @@ { "metadata": { "name": "", - "signature": "sha256:3442b8345ce99d8d379e475a753f23abf3392c6d4a6fdf185cf061e73e09b9e1" + "signature": "sha256:8b17f6649c9b74d878c198037ee831fbec78e7ac375adfc4a62f03266d9d66c3" }, "nbformat": 3, "nbformat_minor": 0, @@ -877,6 +877,85 @@ ], "prompt_number": 8 }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "**Note** \n", + "Some people pointed out the speed difference between Python 3's `range()` and Python2's `xrange()`. Since they are implemented the same way one would expect the same speed. However the difference here just comes from the fact that Python 3 generally tends to run slower than Python 2. " + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "def test_while():\n", + " i = 0\n", + " while i < 20000:\n", + " i += 1\n", + " return" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 3 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "print('Python', python_version())\n", + "%timeit test_while()" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Python 3.4.1\n", + "100 loops, best of 3: 2.68 ms per loop" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n" + ] + } + ], + "prompt_number": 4 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "print 'Python', python_version()\n", + "%timeit test_while()" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Python 2.7.6\n", + "1000 loops, best of 3: 1.72 ms per loop" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n" + ] + } + ], + "prompt_number": 6 + }, { "cell_type": "markdown", "metadata": {},