{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "%load_ext autoreload\n", "%autoreload 2" ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [], "source": [ "from itertools import chain\n", "from utils import prof" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [], "source": [ "def perf(func, *args, **kwargs):\n", " return prof(func, locals(), globals(), *args, **kwargs)" ] }, { "cell_type": "code", "execution_count": 52, "metadata": {}, "outputs": [], "source": [ "results = tuple((i, i + 10) for i in range (1000, 120000))" ] }, { "cell_type": "code", "execution_count": 53, "metadata": {}, "outputs": [], "source": [ "passage = list(range(500, 15000))" ] }, { "cell_type": "code", "execution_count": 94, "metadata": {}, "outputs": [], "source": [ "def highlights1():\n", " hl = set()\n", " for r in results:\n", " for n in r:\n", " if n in passage:\n", " hl.add(n)\n", " return hl" ] }, { "cell_type": "code", "execution_count": 95, "metadata": {}, "outputs": [], "source": [ "def highlights2():\n", " passageSet = set(passage)\n", " hl = set()\n", " for r in results:\n", " for n in r:\n", " if n in passageSet:\n", " hl.add(n)\n", " return hl" ] }, { "cell_type": "code", "execution_count": 96, "metadata": {}, "outputs": [], "source": [ "def highlights3():\n", " passageSet = set(passage)\n", " resultSet = set(chain.from_iterable(results))\n", " return resultSet & passageSet" ] }, { "cell_type": "code", "execution_count": 97, "metadata": {}, "outputs": [], "source": [ "def highlights4():\n", " passageSet = set(passage)\n", " return {n for n in chain.from_iterable(results) if n in passageSet}" ] }, { "cell_type": "code", "execution_count": 98, "metadata": {}, "outputs": [], "source": [ "def highlights5():\n", " passageSet = set(passage)\n", " resultSet = set(chain.from_iterable(results))\n", " return passageSet & resultSet" ] }, { "cell_type": "code", "execution_count": 99, "metadata": {}, "outputs": [], "source": [ "def highlights6():\n", " return set(passage) & set(chain.from_iterable(results))" ] }, { "cell_type": "code", "execution_count": 100, "metadata": {}, "outputs": [], "source": [ "def highlights7():\n", " hl = set(chain.from_iterable(results))\n", " hl &= set(passage)\n", " return hl" ] }, { "cell_type": "code", "execution_count": 101, "metadata": {}, "outputs": [], "source": [ "def highlights8():\n", " hl = set(passage)\n", " hl &= set(chain.from_iterable(results))\n", " return hl" ] }, { "cell_type": "code", "execution_count": 60, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " 27992 function calls in 34.633 seconds\n", "\n", " Ordered by: cumulative time\n", "\n", " ncalls tottime percall cumtime percall filename:lineno(function)\n", " 1 34.630 34.630 34.633 34.633 :1(highlights1)\n", " 27990 0.003 0.000 0.003 0.000 {method 'add' of 'set' objects}\n", " 1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}\n", "\n", "\n", "\n" ] }, { "data": { "text/plain": [ "14000" ] }, "execution_count": 60, "metadata": {}, "output_type": "execute_result" } ], "source": [ "x = perf(highlights1)\n", "len(x)" ] }, { "cell_type": "code", "execution_count": 104, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " 27992 function calls in 0.022 seconds\n", "\n", " Ordered by: cumulative time\n", "\n", " ncalls tottime percall cumtime percall filename:lineno(function)\n", " 1 0.020 0.020 0.022 0.022 :1(highlights2)\n", " 27990 0.002 0.000 0.002 0.000 {method 'add' of 'set' objects}\n", " 1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}\n", "\n", "\n", "\n" ] }, { "data": { "text/plain": [ "14000" ] }, "execution_count": 104, "metadata": {}, "output_type": "execute_result" } ], "source": [ "x = perf(highlights2)\n", "len(x)" ] }, { "cell_type": "code", "execution_count": 111, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " 3 function calls in 0.012 seconds\n", "\n", " Ordered by: cumulative time\n", "\n", " ncalls tottime percall cumtime percall filename:lineno(function)\n", " 1 0.012 0.012 0.012 0.012 :1(highlights3)\n", " 1 0.000 0.000 0.000 0.000 {built-in method from_iterable}\n", " 1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}\n", "\n", "\n", "\n" ] }, { "data": { "text/plain": [ "14000" ] }, "execution_count": 111, "metadata": {}, "output_type": "execute_result" } ], "source": [ "x = perf(highlights3)\n", "len(x)" ] }, { "cell_type": "code", "execution_count": 114, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " 4 function calls in 0.018 seconds\n", "\n", " Ordered by: cumulative time\n", "\n", " ncalls tottime percall cumtime percall filename:lineno(function)\n", " 1 0.000 0.000 0.018 0.018 :1(highlights4)\n", " 1 0.017 0.017 0.017 0.017 :3()\n", " 1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}\n", " 1 0.000 0.000 0.000 0.000 {built-in method from_iterable}\n", "\n", "\n", "\n" ] }, { "data": { "text/plain": [ "14000" ] }, "execution_count": 114, "metadata": {}, "output_type": "execute_result" } ], "source": [ "x = perf(highlights4)\n", "len(x)" ] }, { "cell_type": "code", "execution_count": 123, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " 3 function calls in 0.012 seconds\n", "\n", " Ordered by: cumulative time\n", "\n", " ncalls tottime percall cumtime percall filename:lineno(function)\n", " 1 0.012 0.012 0.012 0.012 :1(highlights5)\n", " 1 0.000 0.000 0.000 0.000 {built-in method from_iterable}\n", " 1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}\n", "\n", "\n", "\n" ] }, { "data": { "text/plain": [ "14000" ] }, "execution_count": 123, "metadata": {}, "output_type": "execute_result" } ], "source": [ "x = perf(highlights5)\n", "len(x)" ] }, { "cell_type": "code", "execution_count": 127, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " 3 function calls in 0.013 seconds\n", "\n", " Ordered by: cumulative time\n", "\n", " ncalls tottime percall cumtime percall filename:lineno(function)\n", " 1 0.013 0.013 0.013 0.013 :1(highlights6)\n", " 1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}\n", " 1 0.000 0.000 0.000 0.000 {built-in method from_iterable}\n", "\n", "\n", "\n" ] }, { "data": { "text/plain": [ "14000" ] }, "execution_count": 127, "metadata": {}, "output_type": "execute_result" } ], "source": [ "x = perf(highlights6)\n", "len(x)" ] }, { "cell_type": "code", "execution_count": 136, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " 3 function calls in 0.014 seconds\n", "\n", " Ordered by: cumulative time\n", "\n", " ncalls tottime percall cumtime percall filename:lineno(function)\n", " 1 0.014 0.014 0.014 0.014 :1(highlights7)\n", " 1 0.000 0.000 0.000 0.000 {built-in method from_iterable}\n", " 1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}\n", "\n", "\n", "\n" ] }, { "data": { "text/plain": [ "14000" ] }, "execution_count": 136, "metadata": {}, "output_type": "execute_result" } ], "source": [ "x = perf(highlights7)\n", "len(x)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "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.7.7" } }, "nbformat": 4, "nbformat_minor": 4 }