Mercurial > hgrepos > Python > libs > ConfigMix
comparison tests/_perf_config.py @ 542:f71d34dda19f
Add an optional C-implementation for configmix.config.unquote and configmix.config.pathstr2path.
This is currently for Python 3.5+.
It is tested with Python 3.7 and Python3.8 (FreeBSD 12.2 amd64, LLVM 10.0.1).
A build for the stable API ("abi3") fails because PyUnicode_New() is currently
not in the stable API.
Also includes are extended tests for unquote() and pathstr2path().
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Fri, 31 Dec 2021 21:24:16 +0100 |
| parents | 9546d38cd3f8 |
| children | 491413368c7c |
comparison
equal
deleted
inserted
replaced
| 541:25b61f0a1958 | 542:f71d34dda19f |
|---|---|
| 13 | 13 |
| 14 | 14 |
| 15 opts = sys.argv[1:] | 15 opts = sys.argv[1:] |
| 16 all = not opts or "all" in opts | 16 all = not opts or "all" in opts |
| 17 | 17 |
| 18 try: | |
| 19 from configmix.config import fast_unquote, fast_pathstr2path | |
| 20 except ImportError: | |
| 21 fast_unquote = fast_pathstr2path = None | |
| 22 | |
| 18 setup = """ | 23 setup = """ |
| 19 import os | 24 import os |
| 20 | 25 |
| 21 import configmix | 26 import configmix |
| 22 import configmix.config | 27 from configmix.config import _HIER_SEPARATOR, quote, py_pathstr2path, py_unquote |
| 28 try: | |
| 29 from configmix.config import fast_unquote, fast_pathstr2path | |
| 30 except ImportError: | |
| 31 fast_unquote = fast_pathstr2path = None | |
| 23 | 32 |
| 24 TESTDATADIR = os.path.join( | 33 TESTDATADIR = os.path.join( |
| 25 os.path.abspath(os.path.dirname(configmix.__file__)), | 34 os.path.abspath(os.path.dirname(configmix.__file__)), |
| 26 "..", | 35 "..", |
| 27 "tests", | 36 "tests", |
| 28 "data") | 37 "data") |
| 29 | |
| 30 unquote = configmix.unquote | |
| 31 quote = configmix.quote | |
| 32 pathstr2path = configmix.pathstr2path | |
| 33 | 38 |
| 34 cfg = configmix.load(os.path.join(TESTDATADIR, "conf_perf.py")) | 39 cfg = configmix.load(os.path.join(TESTDATADIR, "conf_perf.py")) |
| 35 | 40 |
| 36 se = u"" | 41 se = u"" |
| 37 s1 = u"abc.def.hij" | 42 s1 = u"abc.def.hij" |
| 41 | 46 |
| 42 num = 1000000 | 47 num = 1000000 |
| 43 num_quote = 1 * num | 48 num_quote = 1 * num |
| 44 | 49 |
| 45 if all or "quote" in opts or "unquote" in opts or "path" in opts: | 50 if all or "quote" in opts or "unquote" in opts or "path" in opts: |
| 46 print("unquote/nothing/split: %.4f" % timeit.timeit('a = tuple([unquote(vp) for vp in u"abc.def.hij".split(configmix.config._HIER_SEPARATOR)])', setup=setup, number=num_quote)) | 51 print("unquote/nothing/split: %.4f" % timeit.timeit('a = [py_unquote(vp) for vp in u"abc.def.hij".split(_HIER_SEPARATOR)]', setup=setup, number=num_quote)) |
| 47 print("unquote/yes/split: %.4f" % timeit.timeit('a = [unquote(vp) for vp in u"ab%x20.def.h%x2ej".split(configmix.config._HIER_SEPARATOR)]', setup=setup, number=num_quote)) | 52 print("unquote/yes/split: %.4f" % timeit.timeit('a = [py_unquote(vp) for vp in u"ab%x20.def.h%x2ej".split(_HIER_SEPARATOR)]', setup=setup, number=num_quote)) |
| 48 print("unquote/nothing/no-split: %.4f" % timeit.timeit('a = [unquote(vp) for vp in (u"abc," u"def", u"hij")]', setup=setup, number=num_quote)) | 53 print("unquote/nothing/no-split: %.4f" % timeit.timeit('a = [py_unquote(vp) for vp in (u"abc," u"def", u"hij")]', setup=setup, number=num_quote)) |
| 49 print("unquote/yes/no-split: %.4f" % timeit.timeit('a = [unquote(vp) for vp in (u"ab%x20", u"def", u"h%x2ej")]', setup=setup, number=num_quote)) | 54 print("unquote/yes/no-split: %.4f" % timeit.timeit('a = [py_unquote(vp) for vp in (u"ab%x20", u"def", u"h%x2ej")]', setup=setup, number=num_quote)) |
| 50 print("pathstr2path/non-empty: %.4f" % timeit.timeit('a = pathstr2path(s1)', setup=setup, number=num_quote)) | 55 if fast_unquote: |
| 51 print("pathstr2path/empty: %.4f" % timeit.timeit('a = pathstr2path(se)', setup=setup, number=num_quote)) | 56 print("fast-unquote/nothing/split: %.4f" % timeit.timeit('a = [fast_unquote(vp) for vp in u"abc.def.hij".split(_HIER_SEPARATOR)]', setup=setup, number=num_quote)) |
| 57 print("fast-unquote/yes/split: %.4f" % timeit.timeit('a = [fast_unquote(vp) for vp in u"ab%x20.def.h%x2ej".split(_HIER_SEPARATOR)]', setup=setup, number=num_quote)) | |
| 58 print("fast-unquote/nothing/no-split: %.4f" % timeit.timeit('a = [fast_unquote(vp) for vp in (u"abc," u"def", u"hij")]', setup=setup, number=num_quote)) | |
| 59 print("fast-unquote/yes/no-split: %.4f" % timeit.timeit('a = [fast_unquote(vp) for vp in (u"ab%x20", u"def", u"h%x2ej")]', setup=setup, number=num_quote)) | |
| 60 print("pathstr2path/non-empty: %.4f" % timeit.timeit('a = py_pathstr2path(s1)', setup=setup, number=num_quote)) | |
| 61 print("pathstr2path/empty: %.4f" % timeit.timeit('a = py_pathstr2path(se)', setup=setup, number=num_quote)) | |
| 62 if fast_pathstr2path: | |
| 63 print("fast-pathstr2path/non-empty: %.4f" % timeit.timeit('a = fast_pathstr2path(s1)', setup=setup, number=num_quote)) | |
| 64 print("fast-pathstr2path/empty: %.4f" % timeit.timeit('a = fast_pathstr2path(se)', setup=setup, number=num_quote)) | |
| 52 print("quote/nothing: %.4f" % timeit.timeit('a = [quote(vp) for vp in (u"abc", u"def", u"hij")]', setup=setup, number=num_quote)) | 65 print("quote/nothing: %.4f" % timeit.timeit('a = [quote(vp) for vp in (u"abc", u"def", u"hij")]', setup=setup, number=num_quote)) |
| 53 print("quote/yes: %.4f" % timeit.timeit('a = [quote(vp) for vp in (u"ab:c", u"def", u"h.ij")]', setup=setup, number=num_quote)) | 66 print("quote/yes: %.4f" % timeit.timeit('a = [quote(vp) for vp in (u"ab:c", u"def", u"h.ij")]', setup=setup, number=num_quote)) |
| 54 print("="*50) | 67 print("="*50) |
| 55 | 68 |
| 56 if all or "default" in opts or "non-existing" in opts: | 69 if all or "default" in opts or "non-existing" in opts: |
