{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"```sh\n",
"pip3 install sortedcontainers\n",
"```"
]
},
{
"cell_type": "code",
"execution_count": 165,
"metadata": {},
"outputs": [],
"source": [
"from sortedcontainers import SortedSet, SortedList\n",
"from bisect import bisect"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [],
"source": [
"sl = SortedList(i * 10 for i in range(1000000))"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [],
"source": [
"ss = SortedSet(i * 10 for i in range(1000000))"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"s = set(i * 10 for i in range(1000000))"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[130,\n",
" 140,\n",
" 150,\n",
" 160,\n",
" 170,\n",
" 180,\n",
" 190,\n",
" 200,\n",
" 210,\n",
" 220,\n",
" 230,\n",
" 240,\n",
" 250,\n",
" 260,\n",
" 270,\n",
" 280,\n",
" 290,\n",
" 300,\n",
" 310,\n",
" 320,\n",
" 330,\n",
" 340,\n",
" 350,\n",
" 360,\n",
" 370,\n",
" 380,\n",
" 390,\n",
" 400,\n",
" 410,\n",
" 420,\n",
" 430,\n",
" 440,\n",
" 450]"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"list(ss.irange(123, 456))"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"def isin():\n",
" n = 0\n",
" for i in range(100000):\n",
" if i * 2 in s:\n",
" n += 1\n",
" return n"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"20000"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"isin()"
]
},
{
"cell_type": "code",
"execution_count": 41,
"metadata": {},
"outputs": [],
"source": [
"def issin():\n",
" cnts = ss.__contains__\n",
" n = 0\n",
" for i in range(100000):\n",
" if cnts(i * 2):\n",
" n += 1\n",
" return n"
]
},
{
"cell_type": "code",
"execution_count": 42,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"20000"
]
},
"execution_count": 42,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"issin()"
]
},
{
"cell_type": "code",
"execution_count": 58,
"metadata": {},
"outputs": [],
"source": [
"def issin2():\n",
" s = ss._set\n",
" n = 0\n",
" for i in range(100000):\n",
" if i * 2 in s:\n",
" n += 1\n",
" return n"
]
},
{
"cell_type": "code",
"execution_count": 59,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"20000"
]
},
"execution_count": 59,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"issin2()"
]
},
{
"cell_type": "code",
"execution_count": 50,
"metadata": {},
"outputs": [],
"source": [
"def issiin():\n",
" cnts = ss.__contains__\n",
" return sum(1 for i in range(100000) if cnts(i * 2))"
]
},
{
"cell_type": "code",
"execution_count": 51,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"20000"
]
},
"execution_count": 51,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"issiin()"
]
},
{
"cell_type": "code",
"execution_count": 52,
"metadata": {},
"outputs": [],
"source": [
"def islin():\n",
" n = 0\n",
" for i in range(100000):\n",
" if i * 2 in sl:\n",
" n += 1\n",
" return n"
]
},
{
"cell_type": "code",
"execution_count": 53,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"20000"
]
},
"execution_count": 53,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"islin()"
]
},
{
"cell_type": "code",
"execution_count": 54,
"metadata": {},
"outputs": [],
"source": [
"from utils import prof"
]
},
{
"cell_type": "code",
"execution_count": 55,
"metadata": {},
"outputs": [],
"source": [
"def perf(func, *args, **kwargs):\n",
" return prof(func, locals(), globals(), *args, **kwargs)"
]
},
{
"cell_type": "code",
"execution_count": 61,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" 2 function calls in 0.011 seconds\n",
"\n",
" Ordered by: cumulative time\n",
"\n",
" ncalls tottime percall cumtime percall filename:lineno(function)\n",
" 1 0.011 0.011 0.011 0.011 <ipython-input-6-8e16a711c68a>:1(isin)\n",
" 1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}\n",
"\n",
"\n",
"\n"
]
}
],
"source": [
"result = perf(isin)"
]
},
{
"cell_type": "code",
"execution_count": 62,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" 100002 function calls in 0.038 seconds\n",
"\n",
" Ordered by: cumulative time\n",
"\n",
" ncalls tottime percall cumtime percall filename:lineno(function)\n",
" 1 0.024 0.024 0.038 0.038 <ipython-input-41-f46da62b1c24>:1(issin)\n",
" 100000 0.013 0.000 0.013 0.000 /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/sortedcontainers/sortedset.py:194(__contains__)\n",
" 1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}\n",
"\n",
"\n",
"\n"
]
}
],
"source": [
"result = perf(issin)"
]
},
{
"cell_type": "code",
"execution_count": 63,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" 2 function calls in 0.010 seconds\n",
"\n",
" Ordered by: cumulative time\n",
"\n",
" ncalls tottime percall cumtime percall filename:lineno(function)\n",
" 1 0.010 0.010 0.010 0.010 <ipython-input-58-1b12ec682e8a>:1(issin2)\n",
" 1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}\n",
"\n",
"\n",
"\n"
]
}
],
"source": [
"result = perf(issin2)"
]
},
{
"cell_type": "code",
"execution_count": 49,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" 120004 function calls in 0.043 seconds\n",
"\n",
" Ordered by: cumulative time\n",
"\n",
" ncalls tottime percall cumtime percall filename:lineno(function)\n",
" 1 0.000 0.000 0.043 0.043 <ipython-input-47-ee4073e66e27>:1(issiin)\n",
" 1 0.002 0.002 0.043 0.043 {built-in method builtins.sum}\n",
" 20001 0.027 0.000 0.041 0.000 <ipython-input-47-ee4073e66e27>:3(<genexpr>)\n",
" 100000 0.013 0.000 0.013 0.000 /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/sortedcontainers/sortedset.py:194(__contains__)\n",
" 1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}\n",
"\n",
"\n",
"\n"
]
}
],
"source": [
"result = perf(issiin)"
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" 400002 function calls in 0.159 seconds\n",
"\n",
" Ordered by: cumulative time\n",
"\n",
" ncalls tottime percall cumtime percall filename:lineno(function)\n",
" 1 0.024 0.024 0.159 0.159 <ipython-input-21-a6963ac7fe75>:1(islin)\n",
" 100000 0.057 0.000 0.135 0.000 /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/sortedcontainers/sortedlist.py:358(__contains__)\n",
" 200000 0.070 0.000 0.070 0.000 {built-in method _bisect.bisect_left}\n",
" 100000 0.009 0.000 0.009 0.000 {built-in method builtins.len}\n",
" 1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}\n",
"\n",
"\n",
"\n"
]
}
],
"source": [
"result = perf(islin)"
]
},
{
"cell_type": "code",
"execution_count": 67,
"metadata": {},
"outputs": [],
"source": [
"import pickle\n",
"import gzip\n",
"\n",
"GZIP_LEVEL = 2\n",
"PICKLE_PROTOCOL = 4"
]
},
{
"cell_type": "code",
"execution_count": 73,
"metadata": {},
"outputs": [],
"source": [
"def save(data, fileName):\n",
" with gzip.open(fileName, \"wb\", compresslevel=GZIP_LEVEL) as f:\n",
" pickle.dump(data, f, protocol=PICKLE_PROTOCOL)\n",
" \n",
"def load(fileName):\n",
" with gzip.open(fileName, \"rb\") as f:\n",
" return pickle.load(f)"
]
},
{
"cell_type": "code",
"execution_count": 74,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" 664 function calls in 0.110 seconds\n",
"\n",
" Ordered by: cumulative time\n",
"\n",
" ncalls tottime percall cumtime percall filename:lineno(function)\n",
" 1 0.000 0.000 0.110 0.110 <ipython-input-73-6dc37591d02d>:1(save)\n",
" 1 0.028 0.028 0.106 0.106 {built-in method _pickle.dump}\n",
" 77 0.000 0.000 0.077 0.001 /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/gzip.py:247(write)\n",
" 77 0.075 0.001 0.075 0.001 {method 'compress' of 'zlib.Compress' objects}\n",
" 1 0.000 0.000 0.004 0.004 /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/gzip.py:20(open)\n",
" 1 0.000 0.000 0.004 0.004 /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/gzip.py:123(__init__)\n",
" 1 0.004 0.004 0.004 0.004 {built-in method io.open}\n",
" 87 0.002 0.000 0.002 0.000 {method 'write' of '_io.BufferedWriter' objects}\n",
" 78 0.000 0.000 0.000 0.000 {built-in method zlib.crc32}\n",
" 1 0.000 0.000 0.000 0.000 /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/gzip.py:302(close)\n",
" 1 0.000 0.000 0.000 0.000 {method 'close' of '_io.BufferedWriter' objects}\n",
" 1 0.000 0.000 0.000 0.000 {built-in method zlib.compressobj}\n",
" 77 0.000 0.000 0.000 0.000 /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/_compression.py:12(_check_not_closed)\n",
" 1 0.000 0.000 0.000 0.000 {method 'flush' of 'zlib.Compress' objects}\n",
" 1 0.000 0.000 0.000 0.000 /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/gzip.py:221(_write_gzip_header)\n",
" 79 0.000 0.000 0.000 0.000 /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/gzip.py:298(closed)\n",
" 80 0.000 0.000 0.000 0.000 {built-in method builtins.isinstance}\n",
" 77 0.000 0.000 0.000 0.000 {built-in method builtins.len}\n",
" 3 0.000 0.000 0.000 0.000 /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/gzip.py:64(write32u)\n",
" 1 0.000 0.000 0.000 0.000 /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/posixpath.py:144(basename)\n",
" 1 0.000 0.000 0.000 0.000 /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/gzip.py:213(_init_write)\n",
" 3 0.000 0.000 0.000 0.000 {built-in method _struct.pack}\n",
" 1 0.000 0.000 0.000 0.000 /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/posixpath.py:41(_get_sep)\n",
" 2 0.000 0.000 0.000 0.000 {method 'encode' of 'str' objects}\n",
" 1 0.000 0.000 0.000 0.000 {method 'rfind' of 'str' objects}\n",
" 2 0.000 0.000 0.000 0.000 {method 'startswith' of 'str' objects}\n",
" 2 0.000 0.000 0.000 0.000 {built-in method posix.fspath}\n",
" 1 0.000 0.000 0.000 0.000 {built-in method time.time}\n",
" 1 0.000 0.000 0.000 0.000 /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/sortedcontainers/sortedset.py:698(__reduce__)\n",
" 1 0.000 0.000 0.000 0.000 {method 'endswith' of 'bytes' objects}\n",
" 1 0.000 0.000 0.000 0.000 {method 'replace' of 'str' objects}\n",
" 1 0.000 0.000 0.000 0.000 {built-in method builtins.chr}\n",
" 1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}\n",
"\n",
"\n",
"\n"
]
}
],
"source": [
"fileName = '_temp/ss.tfx'\n",
"perf(save, ss, '_temp/ss.tfx')"
]
},
{
"cell_type": "code",
"execution_count": 75,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" 7592 function calls (7287 primitive calls) in 0.279 seconds\n",
"\n",
" Ordered by: cumulative time\n",
"\n",
" ncalls tottime percall cumtime percall filename:lineno(function)\n",
" 1 0.000 0.000 0.279 0.279 <ipython-input-73-6dc37591d02d>:5(load)\n",
" 1 0.063 0.063 0.275 0.275 {built-in method _pickle.load}\n",
" 1 0.007 0.007 0.189 0.189 /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/sortedcontainers/sortedset.py:108(__init__)\n",
" 1 0.050 0.050 0.183 0.183 /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/sortedcontainers/sortedset.py:664(update)\n",
" 2 0.000 0.000 0.112 0.056 /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/sortedcontainers/sortedlist.py:320(update)\n",
" 4 0.000 0.000 0.068 0.017 {method 'extend' of 'list' objects}\n",
" 1002 0.067 0.000 0.067 0.000 /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/sortedcontainers/sortedlist.py:349(<genexpr>)\n",
" 2 0.044 0.022 0.044 0.022 {built-in method builtins.sorted}\n",
" 154 0.000 0.000 0.021 0.000 /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/gzip.py:271(read)\n",
" 469/164 0.002 0.000 0.021 0.000 {method 'read' of '_io.BufferedReader' objects}\n",
" 306 0.001 0.000 0.021 0.000 /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/_compression.py:66(readinto)\n",
" 1 0.020 0.020 0.020 0.020 {method 'update' of 'set' objects}\n",
" 306 0.001 0.000 0.019 0.000 /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/gzip.py:438(read)\n",
" 306 0.015 0.000 0.015 0.000 {method 'decompress' of 'zlib.Decompress' objects}\n",
" 1 0.000 0.000 0.004 0.004 /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/gzip.py:20(open)\n",
" 1 0.000 0.000 0.004 0.004 /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/gzip.py:123(__init__)\n",
" 1 0.004 0.004 0.004 0.004 {built-in method io.open}\n",
" 315 0.000 0.000 0.002 0.000 /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/gzip.py:80(read)\n",
" 306 0.000 0.000 0.001 0.000 /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/gzip.py:489(_add_read_data)\n",
" 154 0.000 0.000 0.001 0.000 /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/gzip.py:291(peek)\n",
" 307 0.000 0.000 0.000 0.000 {built-in method zlib.crc32}\n",
" 154 0.000 0.000 0.000 0.000 {method 'peek' of '_io.BufferedReader' objects}\n",
" 1002 0.000 0.000 0.000 0.000 /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/sortedcontainers/sortedlist.py:351(<genexpr>)\n",
" 308 0.000 0.000 0.000 0.000 /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/_compression.py:12(_check_not_closed)\n",
" 1692 0.000 0.000 0.000 0.000 {built-in method builtins.len}\n",
" 154 0.000 0.000 0.000 0.000 /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/gzip.py:93(prepend)\n",
" 306 0.000 0.000 0.000 0.000 {method 'cast' of 'memoryview' objects}\n",
" 310 0.000 0.000 0.000 0.000 /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/gzip.py:298(closed)\n",
" 1 0.000 0.000 0.000 0.000 /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/gzip.py:302(close)\n",
" 2 0.000 0.000 0.000 0.000 {method 'close' of '_io.BufferedReader' objects}\n",
" 1 0.000 0.000 0.000 0.000 /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/gzip.py:405(_read_gzip_header)\n",
" 1 0.000 0.000 0.000 0.000 /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/gzip.py:378(__init__)\n",
" 1 0.000 0.000 0.000 0.000 /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/sortedcontainers/sortedlist.py:141(__init__)\n",
" 1 0.000 0.000 0.000 0.000 /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/_compression.py:59(close)\n",
" 1 0.000 0.000 0.000 0.000 /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/_compression.py:39(__init__)\n",
" 1 0.000 0.000 0.000 0.000 /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/sortedcontainers/sortedlist.py:171(__new__)\n",
" 1 0.000 0.000 0.000 0.000 /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/sortedcontainers/sortedlist.py:235(clear)\n",
" 1 0.000 0.000 0.000 0.000 {built-in method zlib.decompressobj}\n",
" 1 0.000 0.000 0.000 0.000 /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/gzip.py:74(__init__)\n",
" 1 0.000 0.000 0.000 0.000 /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/gzip.py:385(_init_read)\n",
" 1 0.000 0.000 0.000 0.000 {built-in method _struct.unpack}\n",
" 1 0.000 0.000 0.000 0.000 /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/gzip.py:389(_read_exact)\n",
" 1 0.000 0.000 0.000 0.000 {built-in method __new__ of type object at 0x10fcdff70}\n",
" 1 0.000 0.000 0.000 0.000 {method 'replace' of 'str' objects}\n",
" 1 0.000 0.000 0.000 0.000 {method 'startswith' of 'str' objects}\n",
" 1 0.000 0.000 0.000 0.000 {built-in method builtins.hasattr}\n",
" 1 0.000 0.000 0.000 0.000 {built-in method builtins.isinstance}\n",
" 1 0.000 0.000 0.000 0.000 {built-in method posix.fspath}\n",
" 1 0.000 0.000 0.000 0.000 {function DecompressReader.close at 0x7f9e7009a9d8}\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 /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/_compression.py:36(readable)\n",
" 1 0.000 0.000 0.000 0.000 /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/_compression.py:150(tell)\n",
"\n",
"\n",
"\n"
]
}
],
"source": [
"ss2 = perf(load, fileName)"
]
},
{
"cell_type": "code",
"execution_count": 77,
"metadata": {},
"outputs": [],
"source": [
"import collections"
]
},
{
"cell_type": "code",
"execution_count": 100,
"metadata": {},
"outputs": [],
"source": [
"data = {i * 3: i * 10 for i in range(1_000_000)}"
]
},
{
"cell_type": "code",
"execution_count": 111,
"metadata": {},
"outputs": [],
"source": [
"def none():\n",
" return None\n",
"\n",
"data2 = collections.defaultdict(none, data)"
]
},
{
"cell_type": "code",
"execution_count": 112,
"metadata": {},
"outputs": [],
"source": [
"fileName = '_temp/defaultdict.tfx'\n",
"save(data2, fileName)"
]
},
{
"cell_type": "code",
"execution_count": 113,
"metadata": {},
"outputs": [],
"source": [
"data3 = load(fileName)"
]
},
{
"cell_type": "code",
"execution_count": 114,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 114,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"data3 == data2"
]
},
{
"cell_type": "code",
"execution_count": 115,
"metadata": {},
"outputs": [],
"source": [
"def v(data, n):\n",
" if n in data:\n",
" return data[n]\n",
" return None"
]
},
{
"cell_type": "code",
"execution_count": 116,
"metadata": {},
"outputs": [],
"source": [
"def v2(data, n):\n",
" return data[n]"
]
},
{
"cell_type": "code",
"execution_count": 117,
"metadata": {},
"outputs": [],
"source": [
"def getVal():\n",
" myData = data\n",
" n = 0\n",
" for i in range(100_000):\n",
" if v(data, i) is None:\n",
" n += 1\n",
" return n"
]
},
{
"cell_type": "code",
"execution_count": 118,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"66666"
]
},
"execution_count": 118,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"getVal()"
]
},
{
"cell_type": "code",
"execution_count": 119,
"metadata": {},
"outputs": [],
"source": [
"def getVal2():\n",
" myData = data2\n",
" n = 0\n",
" for i in range(100_000):\n",
" if v2(data2, i) is None:\n",
" n += 1\n",
" return n"
]
},
{
"cell_type": "code",
"execution_count": 120,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"66666"
]
},
"execution_count": 120,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"getVal2()"
]
},
{
"cell_type": "code",
"execution_count": 123,
"metadata": {},
"outputs": [],
"source": [
"def getVal3():\n",
" myData = data2\n",
" n = 0\n",
" for i in range(100_000):\n",
" if data2[i] is None:\n",
" n += 1\n",
" return n"
]
},
{
"cell_type": "code",
"execution_count": 124,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"66666"
]
},
"execution_count": 124,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"getVal3()"
]
},
{
"cell_type": "code",
"execution_count": 121,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" 100002 function calls in 0.040 seconds\n",
"\n",
" Ordered by: cumulative time\n",
"\n",
" ncalls tottime percall cumtime percall filename:lineno(function)\n",
" 1 0.024 0.024 0.040 0.040 <ipython-input-117-ccdfc393b640>:1(getVal)\n",
" 100000 0.017 0.000 0.017 0.000 <ipython-input-115-9c9be12ac0e9>:1(v)\n",
" 1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}\n",
"\n",
"\n",
"\n"
]
},
{
"data": {
"text/plain": [
"66666"
]
},
"execution_count": 121,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"perf(getVal)"
]
},
{
"cell_type": "code",
"execution_count": 122,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" 100002 function calls in 0.041 seconds\n",
"\n",
" Ordered by: cumulative time\n",
"\n",
" ncalls tottime percall cumtime percall filename:lineno(function)\n",
" 1 0.024 0.024 0.041 0.041 <ipython-input-119-a24629a4e9bc>:1(getVal2)\n",
" 100000 0.018 0.000 0.018 0.000 <ipython-input-116-012351b3d7ee>:1(v2)\n",
" 1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}\n",
"\n",
"\n",
"\n"
]
},
{
"data": {
"text/plain": [
"66666"
]
},
"execution_count": 122,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"perf(getVal2)"
]
},
{
"cell_type": "code",
"execution_count": 125,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" 2 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.018 0.018 0.018 0.018 <ipython-input-123-92cbdd8a5b3f>:1(getVal3)\n",
" 1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}\n",
"\n",
"\n",
"\n"
]
},
{
"data": {
"text/plain": [
"66666"
]
},
"execution_count": 125,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"perf(getVal333)"
]
},
{
"cell_type": "code",
"execution_count": 126,
"metadata": {},
"outputs": [],
"source": [
"from tf.app import use"
]
},
{
"cell_type": "code",
"execution_count": 127,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Using TF-app in /Users/dirk/github/annotation/app-bhsa/code:\n",
"\trepo clone offline under ~/github (local github)\n",
"Using data in /Users/dirk/github/etcbc/bhsa/tf/c:\n",
"\trepo clone offline under ~/github (local github)\n",
"Using data in /Users/dirk/github/etcbc/phono/tf/c:\n",
"\trepo clone offline under ~/github (local github)\n",
"Using data in /Users/dirk/github/etcbc/parallels/tf/c:\n",
"\trepo clone offline under ~/github (local github)\n",
" | 0.00s No structure info in otext, the structure part of the T-API cannot be used\n"
]
},
{
"data": {
"text/html": [
"<b>Documentation:</b> <a target=\"_blank\" href=\"https://etcbc.github.io/bhsa\" title=\"provenance of BHSA = Biblia Hebraica Stuttgartensia Amstelodamensis\">BHSA</a> <a target=\"_blank\" href=\"https://annotation.github.io/text-fabric/Writing/Hebrew\" title=\"('Hebrew characters and transcriptions',)\">Character table</a> <a target=\"_blank\" href=\"https://etcbc.github.io/bhsa/features/0_home\" title=\"BHSA feature documentation\">Feature docs</a> <a target=\"_blank\" href=\"https://github.com/annotation/app-bhsa\" title=\"bhsa API documentation\">bhsa API</a> <a target=\"_blank\" href=\"https://annotation.github.io/text-fabric/Api/Fabric/\" title=\"text-fabric-api\">Text-Fabric API 7.8.4</a> <a target=\"_blank\" href=\"https://annotation.github.io/text-fabric/Use/Search/\" title=\"Search Templates Introduction and Reference\">Search Reference</a><details open><summary><b>Loaded features</b>:</summary>\n",
"<p><b>BHSA = Biblia Hebraica Stuttgartensia Amstelodamensis</b>: <a target=\"_blank\" href=\"https://etcbc.github.io/bhsa/features/book\" title=\"/Users/dirk/github/etcbc/bhsa/tf/c/book.tf\">book</a> <a target=\"_blank\" href=\"https://etcbc.github.io/bhsa/features/book@ll\" title=\"/Users/dirk/github/etcbc/bhsa/tf/c/book@am.tf\">book@ll</a> <a target=\"_blank\" href=\"https://etcbc.github.io/bhsa/features/chapter\" title=\"/Users/dirk/github/etcbc/bhsa/tf/c/chapter.tf\">chapter</a> <a target=\"_blank\" href=\"https://etcbc.github.io/bhsa/features/code\" title=\"/Users/dirk/github/etcbc/bhsa/tf/c/code.tf\">code</a> <a target=\"_blank\" href=\"https://etcbc.github.io/bhsa/features/det\" title=\"/Users/dirk/github/etcbc/bhsa/tf/c/det.tf\">det</a> <a target=\"_blank\" href=\"https://etcbc.github.io/bhsa/features/freq_lex\" title=\"/Users/dirk/github/etcbc/bhsa/tf/c/freq_lex.tf\">freq_lex</a> <a target=\"_blank\" href=\"https://etcbc.github.io/bhsa/features/function\" title=\"/Users/dirk/github/etcbc/bhsa/tf/c/function.tf\">function</a> <a target=\"_blank\" href=\"https://etcbc.github.io/bhsa/features/g_cons\" title=\"/Users/dirk/github/etcbc/bhsa/tf/c/g_cons.tf\">g_cons</a> <a target=\"_blank\" href=\"https://etcbc.github.io/bhsa/features/g_cons_utf8\" title=\"/Users/dirk/github/etcbc/bhsa/tf/c/g_cons_utf8.tf\">g_cons_utf8</a> <a target=\"_blank\" href=\"https://etcbc.github.io/bhsa/features/g_lex\" title=\"/Users/dirk/github/etcbc/bhsa/tf/c/g_lex.tf\">g_lex</a> <a target=\"_blank\" href=\"https://etcbc.github.io/bhsa/features/g_lex_utf8\" title=\"/Users/dirk/github/etcbc/bhsa/tf/c/g_lex_utf8.tf\">g_lex_utf8</a> <a target=\"_blank\" href=\"https://etcbc.github.io/bhsa/features/g_word\" title=\"/Users/dirk/github/etcbc/bhsa/tf/c/g_word.tf\">g_word</a> <a target=\"_blank\" href=\"https://etcbc.github.io/bhsa/features/g_word_utf8\" title=\"/Users/dirk/github/etcbc/bhsa/tf/c/g_word_utf8.tf\">g_word_utf8</a> <a target=\"_blank\" href=\"https://etcbc.github.io/bhsa/features/gloss\" title=\"/Users/dirk/github/etcbc/bhsa/tf/c/gloss.tf\">gloss</a> <a target=\"_blank\" href=\"https://etcbc.github.io/bhsa/features/gn\" title=\"/Users/dirk/github/etcbc/bhsa/tf/c/gn.tf\">gn</a> <a target=\"_blank\" href=\"https://etcbc.github.io/bhsa/features/label\" title=\"/Users/dirk/github/etcbc/bhsa/tf/c/label.tf\">label</a> <a target=\"_blank\" href=\"https://etcbc.github.io/bhsa/features/language\" title=\"/Users/dirk/github/etcbc/bhsa/tf/c/language.tf\">language</a> <a target=\"_blank\" href=\"https://etcbc.github.io/bhsa/features/lex\" title=\"/Users/dirk/github/etcbc/bhsa/tf/c/lex.tf\">lex</a> <a target=\"_blank\" href=\"https://etcbc.github.io/bhsa/features/lex_utf8\" title=\"/Users/dirk/github/etcbc/bhsa/tf/c/lex_utf8.tf\">lex_utf8</a> <a target=\"_blank\" href=\"https://etcbc.github.io/bhsa/features/ls\" title=\"/Users/dirk/github/etcbc/bhsa/tf/c/ls.tf\">ls</a> <a target=\"_blank\" href=\"https://etcbc.github.io/bhsa/features/nametype\" title=\"/Users/dirk/github/etcbc/bhsa/tf/c/nametype.tf\">nametype</a> <a target=\"_blank\" href=\"https://etcbc.github.io/bhsa/features/nme\" title=\"/Users/dirk/github/etcbc/bhsa/tf/c/nme.tf\">nme</a> <a target=\"_blank\" href=\"https://etcbc.github.io/bhsa/features/nu\" title=\"/Users/dirk/github/etcbc/bhsa/tf/c/nu.tf\">nu</a> <a target=\"_blank\" href=\"https://etcbc.github.io/bhsa/features/number\" title=\"/Users/dirk/github/etcbc/bhsa/tf/c/number.tf\">number</a> <a target=\"_blank\" href=\"https://etcbc.github.io/bhsa/features/otype\" title=\"/Users/dirk/github/etcbc/bhsa/tf/c/otype.tf\">otype</a> <a target=\"_blank\" href=\"https://etcbc.github.io/bhsa/features/pdp\" title=\"/Users/dirk/github/etcbc/bhsa/tf/c/pdp.tf\">pdp</a> <a target=\"_blank\" href=\"https://etcbc.github.io/bhsa/features/pfm\" title=\"/Users/dirk/github/etcbc/bhsa/tf/c/pfm.tf\">pfm</a> <a target=\"_blank\" href=\"https://etcbc.github.io/bhsa/features/prs\" title=\"/Users/dirk/github/etcbc/bhsa/tf/c/prs.tf\">prs</a> <a target=\"_blank\" href=\"https://etcbc.github.io/bhsa/features/prs_gn\" title=\"/Users/dirk/github/etcbc/bhsa/tf/c/prs_gn.tf\">prs_gn</a> <a target=\"_blank\" href=\"https://etcbc.github.io/bhsa/features/prs_nu\" title=\"/Users/dirk/github/etcbc/bhsa/tf/c/prs_nu.tf\">prs_nu</a> <a target=\"_blank\" href=\"https://etcbc.github.io/bhsa/features/prs_ps\" title=\"/Users/dirk/github/etcbc/bhsa/tf/c/prs_ps.tf\">prs_ps</a> <a target=\"_blank\" href=\"https://etcbc.github.io/bhsa/features/ps\" title=\"/Users/dirk/github/etcbc/bhsa/tf/c/ps.tf\">ps</a> <a target=\"_blank\" href=\"https://etcbc.github.io/bhsa/features/qere\" title=\"/Users/dirk/github/etcbc/bhsa/tf/c/qere.tf\">qere</a> <a target=\"_blank\" href=\"https://etcbc.github.io/bhsa/features/qere_trailer\" title=\"/Users/dirk/github/etcbc/bhsa/tf/c/qere_trailer.tf\">qere_trailer</a> <a target=\"_blank\" href=\"https://etcbc.github.io/bhsa/features/qere_trailer_utf8\" title=\"/Users/dirk/github/etcbc/bhsa/tf/c/qere_trailer_utf8.tf\">qere_trailer_utf8</a> <a target=\"_blank\" href=\"https://etcbc.github.io/bhsa/features/qere_utf8\" title=\"/Users/dirk/github/etcbc/bhsa/tf/c/qere_utf8.tf\">qere_utf8</a> <a target=\"_blank\" href=\"https://etcbc.github.io/bhsa/features/rank_lex\" title=\"/Users/dirk/github/etcbc/bhsa/tf/c/rank_lex.tf\">rank_lex</a> <a target=\"_blank\" href=\"https://etcbc.github.io/bhsa/features/rela\" title=\"/Users/dirk/github/etcbc/bhsa/tf/c/rela.tf\">rela</a> <a target=\"_blank\" href=\"https://etcbc.github.io/bhsa/features/sp\" title=\"/Users/dirk/github/etcbc/bhsa/tf/c/sp.tf\">sp</a> <a target=\"_blank\" href=\"https://etcbc.github.io/bhsa/features/st\" title=\"/Users/dirk/github/etcbc/bhsa/tf/c/st.tf\">st</a> <a target=\"_blank\" href=\"https://etcbc.github.io/bhsa/features/tab\" title=\"/Users/dirk/github/etcbc/bhsa/tf/c/tab.tf\">tab</a> <a target=\"_blank\" href=\"https://etcbc.github.io/bhsa/features/trailer\" title=\"/Users/dirk/github/etcbc/bhsa/tf/c/trailer.tf\">trailer</a> <a target=\"_blank\" href=\"https://etcbc.github.io/bhsa/features/trailer_utf8\" title=\"/Users/dirk/github/etcbc/bhsa/tf/c/trailer_utf8.tf\">trailer_utf8</a> <a target=\"_blank\" href=\"https://etcbc.github.io/bhsa/features/txt\" title=\"/Users/dirk/github/etcbc/bhsa/tf/c/txt.tf\">txt</a> <a target=\"_blank\" href=\"https://etcbc.github.io/bhsa/features/typ\" title=\"/Users/dirk/github/etcbc/bhsa/tf/c/typ.tf\">typ</a> <a target=\"_blank\" href=\"https://etcbc.github.io/bhsa/features/uvf\" title=\"/Users/dirk/github/etcbc/bhsa/tf/c/uvf.tf\">uvf</a> <a target=\"_blank\" href=\"https://etcbc.github.io/bhsa/features/vbe\" title=\"/Users/dirk/github/etcbc/bhsa/tf/c/vbe.tf\">vbe</a> <a target=\"_blank\" href=\"https://etcbc.github.io/bhsa/features/vbs\" title=\"/Users/dirk/github/etcbc/bhsa/tf/c/vbs.tf\">vbs</a> <a target=\"_blank\" href=\"https://etcbc.github.io/bhsa/features/verse\" title=\"/Users/dirk/github/etcbc/bhsa/tf/c/verse.tf\">verse</a> <a target=\"_blank\" href=\"https://etcbc.github.io/bhsa/features/voc_lex\" title=\"/Users/dirk/github/etcbc/bhsa/tf/c/voc_lex.tf\">voc_lex</a> <a target=\"_blank\" href=\"https://etcbc.github.io/bhsa/features/voc_lex_utf8\" title=\"/Users/dirk/github/etcbc/bhsa/tf/c/voc_lex_utf8.tf\">voc_lex_utf8</a> <a target=\"_blank\" href=\"https://etcbc.github.io/bhsa/features/vs\" title=\"/Users/dirk/github/etcbc/bhsa/tf/c/vs.tf\">vs</a> <a target=\"_blank\" href=\"https://etcbc.github.io/bhsa/features/vt\" title=\"/Users/dirk/github/etcbc/bhsa/tf/c/vt.tf\">vt</a> <b><i><a target=\"_blank\" href=\"https://etcbc.github.io/bhsa/features/mother\" title=\"/Users/dirk/github/etcbc/bhsa/tf/c/mother.tf\">mother</a></i></b> <b><i><a target=\"_blank\" href=\"https://etcbc.github.io/bhsa/features/oslots\" title=\"/Users/dirk/github/etcbc/bhsa/tf/c/oslots.tf\">oslots</a></i></b> </p><p><b>Parallel Passages</b>: <b><i><a target=\"_blank\" href=\"https://nbviewer.jupyter.org/github/etcbc/parallels/blob/master/programs/parallels.ipynb\" title=\"/Users/dirk/github/etcbc/parallels/tf/c/crossref.tf\">crossref</a></i></b> </p><p><b>Phonetic Transcriptions</b>: <a target=\"_blank\" href=\"https://nbviewer.jupyter.org/github/etcbc/phono/blob/master/programs/phono.ipynb\" title=\"/Users/dirk/github/etcbc/phono/tf/c/phono.tf\">phono</a> <a target=\"_blank\" href=\"https://nbviewer.jupyter.org/github/etcbc/phono/blob/master/programs/phono.ipynb\" title=\"/Users/dirk/github/etcbc/phono/tf/c/phono_trailer.tf\">phono_trailer</a> </p></details>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<style>\n",
"@font-face {\n",
" font-family: \"Ezra SIL\";\n",
" src:\n",
" local(\"SILEOT.ttf\"),\n",
" url(\"https://github.com/annotation/text-fabric/blob/master/tf/server/static/fonts/SILEOT.woff?raw=true\");\n",
"}\n",
".features {\n",
" font-family: monospace;\n",
" font-size: medium;\n",
" font-weight: bold;\n",
" color: #0a6611;\n",
" display: flex;\n",
" flex-flow: column nowrap;\n",
" padding: 0.1em;\n",
" margin: 0.1em;\n",
" direction: ltr;\n",
"}\n",
".features div,.features span {\n",
" padding: 0;\n",
" margin: -0.1rem 0;\n",
"}\n",
".features .f {\n",
" font-family: sans-serif;\n",
" font-size: x-small;\n",
" font-weight: normal;\n",
" color: #5555bb;\n",
"}\n",
".features .xft {\n",
" color: #000000;\n",
" background-color: #eeeeee;\n",
" font-size: medium;\n",
" margin: 0.1em 0em;\n",
"}\n",
".features .xft .f {\n",
" color: #000000;\n",
" background-color: #eeeeee;\n",
" font-style: italic;\n",
" font-size: small;\n",
" font-weight: normal;\n",
"}\n",
".ltr {\n",
" direction: ltr ! important;\n",
"}\n",
".verse {\n",
" display: flex;\n",
" flex-flow: row wrap;\n",
" direction: rtl;\n",
"}\n",
".vl {\n",
" display: flex;\n",
" flex-flow: column nowrap;\n",
" justify-content: flex-end;\n",
" align-items: flex-end;\n",
" direction: ltr;\n",
" width: 100%;\n",
"}\n",
".outeritem {\n",
" display: flex;\n",
" flex-flow: row wrap;\n",
" direction: rtl;\n",
"}\n",
".sentence,.clause,.phrase {\n",
" margin-top: -1.2em;\n",
" margin-left: 1em;\n",
" background: #ffffff none repeat scroll 0 0;\n",
" padding: 0 0.3em;\n",
" border-style: solid;\n",
" border-radius: 0.2em;\n",
" font-size: small;\n",
" display: block;\n",
" width: fit-content;\n",
" max-width: fit-content;\n",
" direction: ltr;\n",
"}\n",
".atoms {\n",
" display: flex;\n",
" flex-flow: row wrap;\n",
" margin: 0.3em;\n",
" padding: 0.3em;\n",
" direction: rtl;\n",
" background-color: #ffffff;\n",
"}\n",
".satom,.catom,.patom {\n",
" margin: 0.3em;\n",
" padding: 0.3em;\n",
" border-radius: 0.3em;\n",
" border-style: solid;\n",
" display: flex;\n",
" flex-flow: column nowrap;\n",
" direction: rtl;\n",
" background-color: #ffffff;\n",
"}\n",
".sentence {\n",
" border-color: #aa3333;\n",
" border-width: 1px;\n",
"}\n",
".clause {\n",
" border-color: #aaaa33;\n",
" border-width: 1px;\n",
"}\n",
".phrase {\n",
" border-color: #33aaaa;\n",
" border-width: 1px;\n",
"}\n",
".satom {\n",
" border-color: #aa3333;\n",
" border-width: 4px;\n",
"}\n",
".catom {\n",
" border-color: #aaaa33;\n",
" border-width: 3px;\n",
"}\n",
".patom {\n",
" border-color: #33aaaa;\n",
" border-width: 3px;\n",
"}\n",
".word {\n",
" padding: 0.1em;\n",
" margin: 0.1em;\n",
" border-radius: 0.1em;\n",
" border: 1px solid #cccccc;\n",
" display: flex;\n",
" flex-flow: column nowrap;\n",
" direction: rtl;\n",
" background-color: #ffffff;\n",
"}\n",
".lextp {\n",
" padding: 0.1em;\n",
" margin: 0.1em;\n",
" border-radius: 0.1em;\n",
" border: 2px solid #888888;\n",
" width: fit-content;\n",
" display: flex;\n",
" flex-flow: column nowrap;\n",
" direction: rtl;\n",
" background-color: #ffffff;\n",
"}\n",
".occs {\n",
" font-size: x-small;\n",
"}\n",
".satom.l,.catom.l,.patom.l {\n",
" border-left-style: dotted\n",
"}\n",
".satom.r,.catom.r,.patom.r {\n",
" border-right-style: dotted\n",
"}\n",
".satom.lno,.catom.lno,.patom.lno {\n",
" border-left-style: none\n",
"}\n",
".satom.rno,.catom.rno,.patom.rno {\n",
" border-right-style: none\n",
"}\n",
".tr,.tr a:visited,.tr a:link {\n",
" font-family: sans-serif;\n",
" font-size: large;\n",
" color: #000044;\n",
" direction: ltr;\n",
" text-decoration: none;\n",
"}\n",
".trb,.trb a:visited,.trb a:link {\n",
" font-family: sans-serif;\n",
" font-size: normal;\n",
" direction: ltr;\n",
" text-decoration: none;\n",
"}\n",
".prb,.prb a:visited,.prb a:link {\n",
" font-family: sans-serif;\n",
" font-size: large;\n",
" direction: ltr;\n",
" text-decoration: none;\n",
"}\n",
".h,.h a:visited,.h a:link {\n",
" font-family: \"Ezra SIL\", \"SBL Hebrew\", sans-serif;\n",
" font-size: large;\n",
" color: #000044;\n",
" direction: rtl;\n",
" text-decoration: none;\n",
"}\n",
".hb,.hb a:visited,.hb a:link {\n",
" font-family: \"Ezra SIL\", \"SBL Hebrew\", sans-serif;\n",
" font-size: large;\n",
" line-height: 2;\n",
" direction: rtl;\n",
" text-decoration: none;\n",
"}\n",
".vn {\n",
" font-size: small !important;\n",
" padding-right: 1em;\n",
"}\n",
".rela,.function,.typ {\n",
" font-family: monospace;\n",
" font-size: small;\n",
" color: #0000bb;\n",
"}\n",
".pdp,.pdp a:visited,.pdp a:link {\n",
" font-family: monospace;\n",
" font-size: medium;\n",
" color: #0000bb;\n",
" text-decoration: none;\n",
"}\n",
".voc_lex {\n",
" font-family: monospace;\n",
" font-size: medium;\n",
" color: #0000bb;\n",
"}\n",
".vs {\n",
" font-family: monospace;\n",
" font-size: medium;\n",
" font-weight: bold;\n",
" color: #0000bb;\n",
"}\n",
".vt {\n",
" font-family: monospace;\n",
" font-size: medium;\n",
" font-weight: bold;\n",
" color: #0000bb;\n",
"}\n",
".gloss {\n",
" font-family: sans-serif;\n",
" font-size: small;\n",
" font-weight: normal;\n",
" color: #444444;\n",
"}\n",
".vrs {\n",
" font-family: sans-serif;\n",
" font-size: small;\n",
" font-weight: bold;\n",
" color: #444444;\n",
"}\n",
".nd {\n",
" font-family: monospace;\n",
" font-size: x-small;\n",
" color: #999999;\n",
"}\n",
".hl {\n",
" background-color: #ffee66;\n",
"}\n",
"\n",
"tr.tf, td.tf, th.tf {\n",
" text-align: left;\n",
"}\n",
"\n",
"span.hldot {\n",
"\tbackground-color: var(--hl-strong);\n",
"\tborder: 0.2rem solid var(--hl-rim);\n",
"\tborder-radius: 0.4rem;\n",
"\t/*\n",
"\tdisplay: inline-block;\n",
"\twidth: 0.8rem;\n",
"\theight: 0.8rem;\n",
"\t*/\n",
"}\n",
"span.hl {\n",
"\tbackground-color: var(--hl-strong);\n",
"\tborder-width: 0;\n",
"\tborder-radius: 0.1rem;\n",
"\tborder-style: solid;\n",
"}\n",
"\n",
"span.hlup {\n",
"\tborder-color: var(--hl-dark);\n",
"\tborder-width: 0.1rem;\n",
"\tborder-style: solid;\n",
"\tborder-radius: 0.2rem;\n",
" padding: 0.2rem;\n",
"}\n",
"\n",
":root {\n",
"\t--hl-strong: hsla( 60, 100%, 70%, 0.9 );\n",
"\t--hl-rim: hsla( 55, 100%, 60%, 0.9 );\n",
"\t--hl-dark: hsla( 55, 100%, 40%, 0.9 );\n",
"}\n",
"</style>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<details open><summary><b>API members</b>:</summary>\n",
"<a target=\"_blank\" href=\"https://annotation.github.io/text-fabric/Api/Computed/#computed-data\" title=\"doc\">C Computed</a>, <a target=\"_blank\" href=\"https://annotation.github.io/text-fabric/Api/Computed/#computed-data\" title=\"doc\">Call AllComputeds</a>, <a target=\"_blank\" href=\"https://annotation.github.io/text-fabric/Api/Computed/#computed-data\" title=\"doc\">Cs ComputedString</a><br/>\n",
"<a target=\"_blank\" href=\"https://annotation.github.io/text-fabric/Api/Features/#edge-features\" title=\"doc\">E Edge</a>, <a target=\"_blank\" href=\"https://annotation.github.io/text-fabric/Api/Features/#edge-features\" title=\"doc\">Eall AllEdges</a>, <a target=\"_blank\" href=\"https://annotation.github.io/text-fabric/Api/Features/#edge-features\" title=\"doc\">Es EdgeString</a><br/>\n",
"<a target=\"_blank\" href=\"https://annotation.github.io/text-fabric/Api/Fabric/#loading\" title=\"doc\">ensureLoaded</a>, <a target=\"_blank\" href=\"https://annotation.github.io/text-fabric/Api/Fabric/#loading\" title=\"doc\">TF</a>, <a target=\"_blank\" href=\"https://annotation.github.io/text-fabric/Api/Fabric/#loading\" title=\"doc\">ignored</a>, <a target=\"_blank\" href=\"https://annotation.github.io/text-fabric/Api/Fabric/#loading\" title=\"doc\">loadLog</a><br/>\n",
"<a target=\"_blank\" href=\"https://annotation.github.io/text-fabric/Api/Locality/#locality\" title=\"doc\">L Locality</a><br/>\n",
"<a target=\"_blank\" href=\"https://annotation.github.io/text-fabric/Api/Misc/#messaging\" title=\"doc\">cache</a>, <a target=\"_blank\" href=\"https://annotation.github.io/text-fabric/Api/Misc/#messaging\" title=\"doc\">error</a>, <a target=\"_blank\" href=\"https://annotation.github.io/text-fabric/Api/Misc/#messaging\" title=\"doc\">indent</a>, <a target=\"_blank\" href=\"https://annotation.github.io/text-fabric/Api/Misc/#messaging\" title=\"doc\">info</a>, <a target=\"_blank\" href=\"https://annotation.github.io/text-fabric/Api/Misc/#messaging\" title=\"doc\">isSilent</a>, <a target=\"_blank\" href=\"https://annotation.github.io/text-fabric/Api/Misc/#messaging\" title=\"doc\">reset</a>, <a target=\"_blank\" href=\"https://annotation.github.io/text-fabric/Api/Misc/#messaging\" title=\"doc\">setSilent</a>, <a target=\"_blank\" href=\"https://annotation.github.io/text-fabric/Api/Misc/#messaging\" title=\"doc\">silentOff</a>, <a target=\"_blank\" href=\"https://annotation.github.io/text-fabric/Api/Misc/#messaging\" title=\"doc\">silentOn</a>, <a target=\"_blank\" href=\"https://annotation.github.io/text-fabric/Api/Misc/#messaging\" title=\"doc\">warning</a><br/>\n",
"<a target=\"_blank\" href=\"https://annotation.github.io/text-fabric/Api/Nodes/#navigating-nodes\" title=\"doc\">N Nodes</a>, <a target=\"_blank\" href=\"https://annotation.github.io/text-fabric/Api/Nodes/#navigating-nodes\" title=\"doc\">sortKey</a>, <a target=\"_blank\" href=\"https://annotation.github.io/text-fabric/Api/Nodes/#navigating-nodes\" title=\"doc\">sortKeyTuple</a>, <a target=\"_blank\" href=\"https://annotation.github.io/text-fabric/Api/Nodes/#navigating-nodes\" title=\"doc\">otypeRank</a>, <a target=\"_blank\" href=\"https://annotation.github.io/text-fabric/Api/Nodes/#navigating-nodes\" title=\"doc\">sortNodes</a><br/>\n",
"<a target=\"_blank\" href=\"https://annotation.github.io/text-fabric/Api/Features/#node-features\" title=\"doc\">F Feature</a>, <a target=\"_blank\" href=\"https://annotation.github.io/text-fabric/Api/Features/#node-features\" title=\"doc\">Fall AllFeatures</a>, <a target=\"_blank\" href=\"https://annotation.github.io/text-fabric/Api/Features/#node-features\" title=\"doc\">Fs FeatureString</a><br/>\n",
"<a target=\"_blank\" href=\"https://annotation.github.io/text-fabric/Api/Search/#search\" title=\"doc\">S Search</a><br/>\n",
"<a target=\"_blank\" href=\"https://annotation.github.io/text-fabric/Api/Text/#text\" title=\"doc\">T Text</a></details>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"A = use('bhsa:clone', checkout='clone', hoist=globals())"
]
},
{
"cell_type": "code",
"execution_count": 130,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[(1, 426584, 'word'),\n",
" (426585, 426623, 'book'),\n",
" (426624, 427552, 'chapter'),\n",
" (427553, 515673, 'clause'),\n",
" (515674, 606361, 'clause_atom'),\n",
" (606362, 651541, 'half_verse'),\n",
" (651542, 904748, 'phrase'),\n",
" (904749, 1172289, 'phrase_atom'),\n",
" (1172290, 1236016, 'sentence'),\n",
" (1236017, 1300541, 'sentence_atom'),\n",
" (1300542, 1414353, 'subphrase'),\n",
" (1414354, 1437566, 'verse'),\n",
" (1437567, 1446799, 'lex')]"
]
},
"execution_count": 130,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"otypeLines = '''\n",
"1-426584\tword\n",
"426585-426623\tbook\n",
"426624-427552\tchapter\n",
"427553-515673\tclause\n",
"515674-606361\tclause_atom\n",
"606362-651541\thalf_verse\n",
"651542-904748\tphrase\n",
"904749-1172289\tphrase_atom\n",
"1172290-1236016\tsentence\n",
"1236017-1300541\tsentence_atom\n",
"1300542-1414353\tsubphrase\n",
"1414354-1437566\tverse\n",
"1437567-1446799\tlex\n",
"'''.strip().split('\\n')\n",
"\n",
"otypeItems = [x.split('\\t') for x in otypeLines]\n",
"otypeData = [tuple(int(y) for y in x[0].split('-')) + (x[1],) for x in otypeItems]\n",
"otypeData"
]
},
{
"cell_type": "code",
"execution_count": 166,
"metadata": {},
"outputs": [],
"source": [
"otypeBounds = tuple(x[1] for x in otypeData)"
]
},
{
"cell_type": "code",
"execution_count": 167,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"SortedList([426584, 426623, 427552, 515673, 606361, 651541, 904748, 1172289, 1236016, 1300541, 1414353, 1437566, 1446799])"
]
},
"execution_count": 167,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"otypeBoundaries = SortedList(otypeBounds)\n",
"otypeBoundaries"
]
},
{
"cell_type": "code",
"execution_count": 161,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"['word',\n",
" 'book',\n",
" 'chapter',\n",
" 'clause',\n",
" 'clause_atom',\n",
" 'half_verse',\n",
" 'phrase',\n",
" 'phrase_atom',\n",
" 'sentence',\n",
" 'sentence_atom',\n",
" 'subphrase',\n",
" 'verse',\n",
" 'lex']"
]
},
"execution_count": 161,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"otypeTypes = [x[2] for x in otypeData]\n",
"otypeTypes"
]
},
{
"cell_type": "code",
"execution_count": 137,
"metadata": {},
"outputs": [],
"source": [
"def otype(n):\n",
" i = otypeBoundaries.bisect_left(n)\n",
" return otypeTypes[i]"
]
},
{
"cell_type": "code",
"execution_count": 138,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'word'"
]
},
"execution_count": 138,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"otype(1)"
]
},
{
"cell_type": "code",
"execution_count": 139,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'word'"
]
},
"execution_count": 139,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"otype(426584)"
]
},
{
"cell_type": "code",
"execution_count": 140,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'book'"
]
},
"execution_count": 140,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"otype(426585)"
]
},
{
"cell_type": "code",
"execution_count": 144,
"metadata": {},
"outputs": [],
"source": [
"from random import randrange\n",
"from itertools import repeat"
]
},
{
"cell_type": "code",
"execution_count": 145,
"metadata": {},
"outputs": [],
"source": [
"maxNode = 1446799"
]
},
{
"cell_type": "code",
"execution_count": 146,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"1446799"
]
},
"execution_count": 146,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"F.otype.maxNode"
]
},
{
"cell_type": "code",
"execution_count": 149,
"metadata": {},
"outputs": [],
"source": [
"testIndices = tuple(randrange(1, maxNode) for _ in repeat(None, 100_000))"
]
},
{
"cell_type": "code",
"execution_count": 151,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(941571,\n",
" 1403341,\n",
" 738684,\n",
" 1188363,\n",
" 1090465,\n",
" 1298727,\n",
" 351774,\n",
" 715335,\n",
" 857806,\n",
" 188920)"
]
},
"execution_count": 151,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"testIndices[0:10]"
]
},
{
"cell_type": "code",
"execution_count": 168,
"metadata": {},
"outputs": [],
"source": [
"def getOtype():\n",
" fOtype = F.otype.v\n",
" WORD = 'word'\n",
" n = 0\n",
" for i in testIndices:\n",
" if fOtype(i) == WORD:\n",
" n += 1\n",
" return n"
]
},
{
"cell_type": "code",
"execution_count": 169,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"29372"
]
},
"execution_count": 169,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"getOtype()"
]
},
{
"cell_type": "code",
"execution_count": 154,
"metadata": {},
"outputs": [],
"source": [
"def getOtype2():\n",
" WORD = 'word'\n",
" n = 0\n",
" for i in testIndices:\n",
" j = otypeBoundaries.bisect_left(i)\n",
" thisOtype = otypeTypes[j]\n",
" if thisOtype == WORD:\n",
" n += 1\n",
" return n"
]
},
{
"cell_type": "code",
"execution_count": 155,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"29372"
]
},
"execution_count": 155,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"getOtype2()"
]
},
{
"cell_type": "code",
"execution_count": 158,
"metadata": {},
"outputs": [],
"source": [
"def getOtype3():\n",
" fOtype = otype\n",
" WORD = 'word'\n",
" n = 0\n",
" for i in testIndices:\n",
" if fOtype(i) == WORD:\n",
" n += 1\n",
" return n"
]
},
{
"cell_type": "code",
"execution_count": 159,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"29372"
]
},
"execution_count": 159,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"getOtype3()"
]
},
{
"cell_type": "code",
"execution_count": 170,
"metadata": {},
"outputs": [],
"source": [
"def getOtype4():\n",
" WORD = 'word'\n",
" bs = otypeBoundaries.bisect_left\n",
" otypes = otypeTypes\n",
" n = 0\n",
" for i in testIndices:\n",
" j = bs(i)\n",
" thisOtype = otypes[j]\n",
" if thisOtype == WORD:\n",
" n += 1\n",
" return n"
]
},
{
"cell_type": "code",
"execution_count": 171,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"29372"
]
},
"execution_count": 171,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"getOtype4()"
]
},
{
"cell_type": "code",
"execution_count": 172,
"metadata": {},
"outputs": [],
"source": [
"def getOtype5():\n",
" WORD = 'word'\n",
" bs = bisect\n",
" obounds = otypeBounds\n",
" otypes = otypeTypes\n",
" n = 0\n",
" for i in testIndices:\n",
" j = bs(otypeBounds, i)\n",
" thisOtype = otypes[j]\n",
" if thisOtype == WORD:\n",
" n += 1\n",
" return n"
]
},
{
"cell_type": "code",
"execution_count": 173,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"29372"
]
},
"execution_count": 173,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"getOtype5()"
]
},
{
"cell_type": "code",
"execution_count": 179,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" 170630 function calls in 0.081 seconds\n",
"\n",
" Ordered by: cumulative time\n",
"\n",
" ncalls tottime percall cumtime percall filename:lineno(function)\n",
" 1 0.022 0.022 0.081 0.081 <ipython-input-168-bdc432e5e397>:1(getOtype)\n",
" 100000 0.053 0.000 0.059 0.000 /Users/dirk/github/annotation/text-fabric/tf/core/api.py:80(v)\n",
" 70628 0.006 0.000 0.006 0.000 {built-in method builtins.len}\n",
" 1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}\n",
"\n",
"\n",
"\n"
]
},
{
"data": {
"text/plain": [
"29372"
]
},
"execution_count": 179,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"perf(getOtype)"
]
},
{
"cell_type": "code",
"execution_count": 180,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" 100002 function calls in 0.045 seconds\n",
"\n",
" Ordered by: cumulative time\n",
"\n",
" ncalls tottime percall cumtime percall filename:lineno(function)\n",
" 1 0.020 0.020 0.045 0.045 <ipython-input-172-07b0e4b56f55>:1(getOtype5)\n",
" 100000 0.025 0.000 0.025 0.000 {built-in method _bisect.bisect_right}\n",
" 1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}\n",
"\n",
"\n",
"\n"
]
},
{
"data": {
"text/plain": [
"29372"
]
},
"execution_count": 180,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"perf(getOtype5)"
]
},
{
"cell_type": "code",
"execution_count": 175,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" 500002 function calls in 0.160 seconds\n",
"\n",
" Ordered by: cumulative time\n",
"\n",
" ncalls tottime percall cumtime percall filename:lineno(function)\n",
" 1 0.030 0.030 0.160 0.160 <ipython-input-154-f3bcda24181d>:1(getOtype2)\n",
" 100000 0.072 0.000 0.130 0.000 /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/sortedcontainers/sortedlist.py:1154(bisect_left)\n",
" 200000 0.040 0.000 0.040 0.000 {built-in method _bisect.bisect_left}\n",
" 100000 0.010 0.000 0.010 0.000 /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/sortedcontainers/sortedlist.py:516(_loc)\n",
" 100000 0.008 0.000 0.008 0.000 {built-in method builtins.len}\n",
" 1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}\n",
"\n",
"\n",
"\n"
]
},
{
"data": {
"text/plain": [
"29372"
]
},
"execution_count": 175,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"perf(getOtype2)"
]
},
{
"cell_type": "code",
"execution_count": 176,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" 600002 function calls in 0.179 seconds\n",
"\n",
" Ordered by: cumulative time\n",
"\n",
" ncalls tottime percall cumtime percall filename:lineno(function)\n",
" 1 0.017 0.017 0.179 0.179 <ipython-input-158-13efc3c2776b>:1(getOtype3)\n",
" 100000 0.033 0.000 0.162 0.000 <ipython-input-137-9b663aff1655>:1(otype)\n",
" 100000 0.072 0.000 0.129 0.000 /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/sortedcontainers/sortedlist.py:1154(bisect_left)\n",
" 200000 0.040 0.000 0.040 0.000 {built-in method _bisect.bisect_left}\n",
" 100000 0.009 0.000 0.009 0.000 /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/sortedcontainers/sortedlist.py:516(_loc)\n",
" 100000 0.008 0.000 0.008 0.000 {built-in method builtins.len}\n",
" 1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}\n",
"\n",
"\n",
"\n"
]
},
{
"data": {
"text/plain": [
"29372"
]
},
"execution_count": 176,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"perf(getOtype3)"
]
},
{
"cell_type": "code",
"execution_count": 177,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" 500002 function calls in 0.150 seconds\n",
"\n",
" Ordered by: cumulative time\n",
"\n",
" ncalls tottime percall cumtime percall filename:lineno(function)\n",
" 1 0.022 0.022 0.150 0.150 <ipython-input-170-5fb2c76bc84a>:1(getOtype4)\n",
" 100000 0.070 0.000 0.128 0.000 /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/sortedcontainers/sortedlist.py:1154(bisect_left)\n",
" 200000 0.040 0.000 0.040 0.000 {built-in method _bisect.bisect_left}\n",
" 100000 0.009 0.000 0.009 0.000 /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/sortedcontainers/sortedlist.py:516(_loc)\n",
" 100000 0.008 0.000 0.008 0.000 {built-in method builtins.len}\n",
" 1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}\n",
"\n",
"\n",
"\n"
]
},
{
"data": {
"text/plain": [
"29372"
]
},
"execution_count": 177,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"perf(getOtype4)"
]
},
{
"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.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
}