Commit 3bb9426f authored by Loic Huder's avatar Loic Huder
Browse files

Removed except:

parent 45f02d76
Pipeline #33210 passed with stage
in 1 minute and 1 second
...@@ -38,16 +38,7 @@ ...@@ -38,16 +38,7 @@
"cell_type": "code", "cell_type": "code",
"execution_count": 1, "execution_count": 1,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [],
{
"name": "stdout",
"output_type": "stream",
"text": [
"['a', 2] [0, 1, 2] ['a', 2, 0, 1, 2]\n",
"['a', 2, 'a', 2, 'a', 2]\n"
]
}
],
"source": [ "source": [
"# 2 equivalent ways to define an empty list\n", "# 2 equivalent ways to define an empty list\n",
"l0 = []\n", "l0 = []\n",
...@@ -570,8 +561,8 @@ ...@@ -570,8 +561,8 @@
"name": "stdout", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"integer remove from the list: 12\n", "integer remove from the list: 3\n",
"shuffled list: [6, 15, 7, 1, 0, 8, 2, 19, 10, 17, 11, 3, 9, 14, 16, 4, 18, 13, 5]\n" "shuffled list: [13, 6, 8, 7, 15, 0, 14, 17, 11, 1, 18, 16, 10, 4, 2, 5, 12, 9, 19]\n"
] ]
} }
], ],
...@@ -616,7 +607,7 @@ ...@@ -616,7 +607,7 @@
{ {
"data": { "data": {
"text/plain": [ "text/plain": [
"12" "3"
] ]
}, },
"execution_count": 21, "execution_count": 21,
...@@ -1022,21 +1013,21 @@ ...@@ -1022,21 +1013,21 @@
"name": "stdout", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"len(s) = 7160000, nbkeys 33 base, count, count_count, except, colection.counter\n", "len(s) = 7160000, nbkeys 33 base, count, count_count, except, collections.Counter\n",
"747 ms ± 51.8 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n", "723 ms ± 9.23 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
"692 ms ± 42.2 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n", "750 ms ± 45 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
"286 ms ± 9.76 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n", "270 ms ± 5.72 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
"667 ms ± 25.1 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n", "702 ms ± 28.9 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
"355 ms ± 11.9 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n", "510 ms ± 82.7 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
"572 ms ± 9.46 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n", "661 ms ± 47.3 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
"with split\n", "with split\n",
"len(s) = 1100000, nbkeys 90 base, count, count_count, except, colection.counter\n", "len(s) = 1100000, nbkeys 90 base, count, count_count, except, collections.Counter\n",
"142 ms ± 2.51 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)\n", "182 ms ± 19.3 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
"147 ms ± 7.07 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)\n", "152 ms ± 2.21 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)\n",
"1.71 s ± 184 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n", "1.58 s ± 64.1 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
"126 ms ± 4.58 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)\n", "130 ms ± 2.73 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)\n",
"78.9 ms ± 1.87 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)\n", "87.6 ms ± 4.21 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)\n",
"658 ms ± 65.1 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n" "614 ms ± 4.58 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n"
] ]
} }
], ],
...@@ -1060,12 +1051,12 @@ ...@@ -1060,12 +1051,12 @@
" d = {k:t.count(k) for k in set(t)}\n", " d = {k:t.count(k) for k in set(t)}\n",
" return d\n", " return d\n",
"\n", "\n",
"def build_count_excpt(t): \n", "def build_count_except(t): \n",
" d = {} \n", " d = {} \n",
" for s in t:\n", " for s in t:\n",
" try: \n", " try: \n",
" d[s] += 1\n", " d[s] += 1\n",
" except:\n", " except KeyError:\n",
" d[s] = 1\n", " d[s] = 1\n",
" return d\n", " return d\n",
"\n", "\n",
...@@ -1082,22 +1073,21 @@ ...@@ -1082,22 +1073,21 @@
"\n", "\n",
"s = \"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam tristique at velit in varius. Cras ut ultricies orci. Fusce vel consequat ante, vitae luctus tortor. Sed condimentum faucibus enim, sit amet pulvinar ligula feugiat ac. Sed interdum id risus id rhoncus. Nullam nisi justo, ultrices eu est nec, hendrerit maximus lorem. Nam urna eros, accumsan nec magna eu, elementum semper diam. Nulla tempus, nibh id elementum dapibus, ex diam lacinia est, sit amet suscipit nulla nibh eu sapien. Aliquam orci enim, malesuada in facilisis vitae, pharetra sit amet mi. Pellentesque mi tortor, sagittis quis odio quis, fermentum faucibus ex. Aenean sagittis nisl orci. Maecenas tristique velit sed leo facilisis porttitor. \"\n", "s = \"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam tristique at velit in varius. Cras ut ultricies orci. Fusce vel consequat ante, vitae luctus tortor. Sed condimentum faucibus enim, sit amet pulvinar ligula feugiat ac. Sed interdum id risus id rhoncus. Nullam nisi justo, ultrices eu est nec, hendrerit maximus lorem. Nam urna eros, accumsan nec magna eu, elementum semper diam. Nulla tempus, nibh id elementum dapibus, ex diam lacinia est, sit amet suscipit nulla nibh eu sapien. Aliquam orci enim, malesuada in facilisis vitae, pharetra sit amet mi. Pellentesque mi tortor, sagittis quis odio quis, fermentum faucibus ex. Aenean sagittis nisl orci. Maecenas tristique velit sed leo facilisis porttitor. \"\n",
"s = s*10000\n", "s = s*10000\n",
"len(s)\n", "print(f\"len(s) = {len(s)}, nbkeys {len(set(s))} base, count, count_count, except, collections.Counter\")\n",
"print(f\"len(s) = {len(s)}, nbkeys {len(set(s))} base, count, count_count, except, colection.counter\")\n",
"%timeit build_count_base(s)\n", "%timeit build_count_base(s)\n",
"%timeit build_count_set(s)\n", "%timeit build_count_set(s)\n",
"%timeit build_count_count(s)\n", "%timeit build_count_count(s)\n",
"%timeit build_count_excpt(s)\n", "%timeit build_count_except(s)\n",
"%timeit build_count_counter(s)\n", "%timeit build_count_counter(s)\n",
"%timeit build_count_defaultdict(s)\n", "%timeit build_count_defaultdict(s)\n",
"\n", "\n",
"print(\"with split\")\n", "print(\"with split\")\n",
"s2 = s.split()\n", "s2 = s.split()\n",
"print(f\"len(s) = {len(s2)}, nbkeys {len(set(s2))} base, count, count_count, except, colection.counter\")\n", "print(f\"len(s) = {len(s2)}, nbkeys {len(set(s2))} base, count, count_count, except, collections.Counter\")\n",
"%timeit build_count_base(s2)\n", "%timeit build_count_base(s2)\n",
"%timeit build_count_set(s2)\n", "%timeit build_count_set(s2)\n",
"%timeit build_count_count(s2)\n", "%timeit build_count_count(s2)\n",
"%timeit build_count_excpt(s2)\n", "%timeit build_count_except(s2)\n",
"%timeit build_count_counter(s2)\n", "%timeit build_count_counter(s2)\n",
"%timeit build_count_defaultdict(s2)\n", "%timeit build_count_defaultdict(s2)\n",
"\n" "\n"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment