|
1 | 1 | { |
2 | 2 | "metadata": { |
3 | 3 | "name": "", |
4 | | - "signature": "sha256:53ee36d6fcce5f6dbce838e41d83e62fbb143538fe3ca1b0f3cd9b5505e5d786" |
| 4 | + "signature": "sha256:1a71ccc70829239143d02cebcb97bec031b45e676ebad340fc04c9bd4a5760bf" |
5 | 5 | }, |
6 | 6 | "nbformat": 3, |
7 | 7 | "nbformat_minor": 0, |
|
349 | 349 | "output_type": "stream", |
350 | 350 | "stream": "stdout", |
351 | 351 | "text": [ |
352 | | - "Python 2.7.6\n", |
| 352 | + "Python 2.7.7\n", |
353 | 353 | "('a', 'b')\n", |
354 | 354 | "a b\n" |
355 | 355 | ] |
356 | 356 | } |
357 | 357 | ], |
358 | | - "prompt_number": 4 |
| 358 | + "prompt_number": 2 |
359 | 359 | }, |
360 | 360 | { |
361 | 361 | "cell_type": "markdown", |
|
739 | 739 | "\n", |
740 | 740 | "n = 10000\n", |
741 | 741 | "def test_range(n):\n", |
742 | | - " for i in range(n):\n", |
| 742 | + " return for i in range(n):\n", |
743 | 743 | " pass\n", |
744 | 744 | " \n", |
745 | 745 | "def test_xrange(n):\n", |
|
912 | 912 | "language": "python", |
913 | 913 | "metadata": {}, |
914 | 914 | "outputs": [], |
915 | | - "prompt_number": 4 |
| 915 | + "prompt_number": 3 |
916 | 916 | }, |
917 | 917 | { |
918 | 918 | "cell_type": "code", |
919 | 919 | "collapsed": false, |
920 | 920 | "input": [ |
921 | 921 | "def val_in_range(x, val):\n", |
922 | | - " if val in range(x):\n", |
923 | | - " return True\n", |
924 | | - " else:\n", |
925 | | - " return False" |
| 922 | + " return val in range(x)" |
926 | 923 | ], |
927 | 924 | "language": "python", |
928 | 925 | "metadata": {}, |
929 | 926 | "outputs": [], |
930 | | - "prompt_number": 10 |
| 927 | + "prompt_number": 4 |
931 | 928 | }, |
932 | 929 | { |
933 | 930 | "cell_type": "code", |
934 | 931 | "collapsed": false, |
935 | 932 | "input": [ |
936 | 933 | "def val_in_xrange(x, val):\n", |
937 | | - " if val in range(x):\n", |
938 | | - " return True\n", |
939 | | - " else:\n", |
940 | | - " return False" |
| 934 | + " return val in xrange(x)" |
941 | 935 | ], |
942 | 936 | "language": "python", |
943 | 937 | "metadata": {}, |
|
961 | 955 | "output_type": "stream", |
962 | 956 | "stream": "stdout", |
963 | 957 | "text": [ |
964 | | - "Python 3.3.5\n", |
965 | | - "1 loops, best of 3: 751 ms per loop" |
| 958 | + "Python 3.4.1\n", |
| 959 | + "1 loops, best of 3: 742 ms per loop" |
966 | 960 | ] |
967 | 961 | }, |
968 | 962 | { |
969 | 963 | "output_type": "stream", |
970 | 964 | "stream": "stdout", |
971 | 965 | "text": [ |
972 | 966 | "\n", |
973 | | - "1000000 loops, best of 3: 1.21 \u00b5s per loop" |
| 967 | + "1000000 loops, best of 3: 1.19 \u00b5s per loop" |
974 | 968 | ] |
975 | 969 | }, |
976 | 970 | { |
|
981 | 975 | ] |
982 | 976 | } |
983 | 977 | ], |
984 | | - "prompt_number": 11 |
| 978 | + "prompt_number": 7 |
985 | 979 | }, |
986 | 980 | { |
987 | 981 | "cell_type": "markdown", |
|
1004 | 998 | "print 'Python', python_version()\n", |
1005 | 999 | "assert(val_in_xrange(x, x/2.0) == True)\n", |
1006 | 1000 | "assert(val_in_xrange(x, x/2) == True)\n", |
| 1001 | + "assert(val_in_range(x, x/2) == True)\n", |
| 1002 | + "assert(val_in_range(x, x//2) == True)\n", |
1007 | 1003 | "%timeit val_in_xrange(x, x/2.0)\n", |
1008 | | - "%timeit val_in_xrange(x, x/2)" |
| 1004 | + "%timeit val_in_xrange(x, x/2)\n", |
| 1005 | + "%timeit val_in_range(x, x/2.0)\n", |
| 1006 | + "%timeit val_in_range(x, x/2)" |
1009 | 1007 | ], |
1010 | 1008 | "language": "python", |
1011 | 1009 | "metadata": {}, |
|
1015 | 1013 | "stream": "stdout", |
1016 | 1014 | "text": [ |
1017 | 1015 | "Python 2.7.7\n", |
1018 | | - "1 loops, best of 3: 661 ms per loop" |
| 1016 | + "1 loops, best of 3: 285 ms per loop" |
1019 | 1017 | ] |
1020 | 1018 | }, |
1021 | 1019 | { |
1022 | 1020 | "output_type": "stream", |
1023 | 1021 | "stream": "stdout", |
1024 | 1022 | "text": [ |
1025 | 1023 | "\n", |
1026 | | - "1 loops, best of 3: 564 ms per loop" |
| 1024 | + "1 loops, best of 3: 179 ms per loop" |
| 1025 | + ] |
| 1026 | + }, |
| 1027 | + { |
| 1028 | + "output_type": "stream", |
| 1029 | + "stream": "stdout", |
| 1030 | + "text": [ |
| 1031 | + "\n", |
| 1032 | + "1 loops, best of 3: 658 ms per loop" |
| 1033 | + ] |
| 1034 | + }, |
| 1035 | + { |
| 1036 | + "output_type": "stream", |
| 1037 | + "stream": "stdout", |
| 1038 | + "text": [ |
| 1039 | + "\n", |
| 1040 | + "1 loops, best of 3: 556 ms per loop" |
1027 | 1041 | ] |
1028 | 1042 | }, |
1029 | 1043 | { |
|
1070 | 1084 | { |
1071 | 1085 | "metadata": {}, |
1072 | 1086 | "output_type": "pyout", |
1073 | | - "prompt_number": 2, |
| 1087 | + "prompt_number": 8, |
1074 | 1088 | "text": [ |
1075 | 1089 | "<slot wrapper '__contains__' of 'range' objects>" |
1076 | 1090 | ] |
1077 | 1091 | } |
1078 | 1092 | ], |
1079 | | - "prompt_number": 2 |
| 1093 | + "prompt_number": 8 |
1080 | 1094 | }, |
1081 | 1095 | { |
1082 | 1096 | "cell_type": "code", |
|
0 commit comments