Mercurial > hgrepos > Python > libs > ConfigMix
comparison tests/_perf_config.py @ 543:491413368c7c
Added also a fast C-implementation of configmix.config._split_ns
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Sat, 01 Jan 2022 18:01:32 +0100 |
| parents | f71d34dda19f |
| children | 79db28e879f8 |
comparison
equal
deleted
inserted
replaced
| 542:f71d34dda19f | 543:491413368c7c |
|---|---|
| 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: | 18 try: |
| 19 from configmix.config import fast_unquote, fast_pathstr2path | 19 from configmix.config import fast_unquote, fast_pathstr2path, _fast_split_ns |
| 20 except ImportError: | 20 except ImportError: |
| 21 fast_unquote = fast_pathstr2path = None | 21 fast_unquote = fast_pathstr2path = _fast_split_ns = None |
| 22 | 22 |
| 23 setup = """ | 23 setup = """ |
| 24 import os | 24 import os |
| 25 | 25 |
| 26 import configmix | 26 import configmix |
| 27 from configmix.config import _HIER_SEPARATOR, quote, py_pathstr2path, py_unquote | 27 from configmix.config import _HIER_SEPARATOR, quote, py_pathstr2path, \ |
| 28 py_unquote, _py_split_ns | |
| 28 try: | 29 try: |
| 29 from configmix.config import fast_unquote, fast_pathstr2path | 30 from configmix.config import fast_unquote, fast_pathstr2path, _fast_split_ns |
| 30 except ImportError: | 31 except ImportError: |
| 31 fast_unquote = fast_pathstr2path = None | 32 fast_unquote = fast_pathstr2path = _fast_split_ns = None |
| 32 | 33 |
| 33 TESTDATADIR = os.path.join( | 34 TESTDATADIR = os.path.join( |
| 34 os.path.abspath(os.path.dirname(configmix.__file__)), | 35 os.path.abspath(os.path.dirname(configmix.__file__)), |
| 35 "..", | 36 "..", |
| 36 "tests", | 37 "tests", |
| 38 | 39 |
| 39 cfg = configmix.load(os.path.join(TESTDATADIR, "conf_perf.py")) | 40 cfg = configmix.load(os.path.join(TESTDATADIR, "conf_perf.py")) |
| 40 | 41 |
| 41 se = u"" | 42 se = u"" |
| 42 s1 = u"abc.def.hij" | 43 s1 = u"abc.def.hij" |
| 44 ns_s1 = u"PY:abc.def.hij" | |
| 43 | 45 |
| 44 """ | 46 """ |
| 45 | 47 |
| 46 | 48 |
| 47 num = 1000000 | 49 num = 1000000 |
| 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)) | 56 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)) |
| 55 if fast_unquote: | 57 if fast_unquote: |
| 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)) | 58 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)) | 59 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)) | 60 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)) | 61 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)) | 62 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)) | 63 print("pathstr2path/empty: %.4f" % timeit.timeit('a = py_pathstr2path(se)', setup=setup, number=num_quote)) |
| 62 if fast_pathstr2path: | 64 if fast_pathstr2path: |
| 63 print("fast-pathstr2path/non-empty: %.4f" % timeit.timeit('a = fast_pathstr2path(s1)', setup=setup, number=num_quote)) | 65 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)) | 66 print("fast-pathstr2path/empty: %.4f" % timeit.timeit('a = fast_pathstr2path(se)', 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)) | 67 print("quote/nothing: %.4f" % timeit.timeit('a = [quote(vp) for vp in (u"abc", u"def", u"hij")]', 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)) | 68 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)) |
| 69 print("split-ns/no-ns: %.4f" % timeit.timeit('a = _py_split_ns(s1)', setup=setup, number=num_quote)) | |
| 70 print("split-ns/ns: %.4f" % timeit.timeit('a = _py_split_ns(ns_s1)', setup=setup, number=num_quote)) | |
| 71 if _fast_split_ns: | |
| 72 print("fast-split-ns/no-ns: %.4f" % timeit.timeit('a = _fast_split_ns(s1)', setup=setup, number=num_quote)) | |
| 73 print("fast-split-ns/ns: %.4f" % timeit.timeit('a = _fast_split_ns(ns_s1)', setup=setup, number=num_quote)) | |
| 67 print("="*50) | 74 print("="*50) |
| 68 | 75 |
| 69 if all or "default" in opts or "non-existing" in opts: | 76 if all or "default" in opts or "non-existing" in opts: |
| 70 print("default: %.4f" % timeit.timeit('cfg.getvarl(u"tree1", u"yyy", default=None)', setup=setup, number=num)) | 77 print("default: %.4f" % timeit.timeit('cfg.getvarl(u"tree1", u"yyy", default=None)', setup=setup, number=num)) |
| 71 print("default: %.4f" % timeit.timeit('cfg.getvarl_s(u"tree1", u"yyy", default=None)', setup=setup, number=num)) | 78 print("default: %.4f" % timeit.timeit('cfg.getvarl_s(u"tree1", u"yyy", default=None)', setup=setup, number=num)) |
| 90 if all or "expand-string-one-noncached" in opts: | 97 if all or "expand-string-one-noncached" in opts: |
| 91 print("expand-string-one-noncached: %.4f" % timeit.timeit('cfg.getvarl(u"tree1", u"tree2", "key12")', setup=setup, number=num)) | 98 print("expand-string-one-noncached: %.4f" % timeit.timeit('cfg.getvarl(u"tree1", u"tree2", "key12")', setup=setup, number=num)) |
| 92 print("expand-string-one-noncached: %.4f" % timeit.timeit('cfg.getvarl_s(u"tree1", u"tree2", "key12")', setup=setup, number=num)) | 99 print("expand-string-one-noncached: %.4f" % timeit.timeit('cfg.getvarl_s(u"tree1", u"tree2", "key12")', setup=setup, number=num)) |
| 93 print("expand-string-one-noncached: %.4f" % timeit.timeit('cfg.getvar(u"tree1.tree2.key12")', setup=setup, number=num)) | 100 print("expand-string-one-noncached: %.4f" % timeit.timeit('cfg.getvar(u"tree1.tree2.key12")', setup=setup, number=num)) |
| 94 print("expand-string-one-noncached: %.4f" % timeit.timeit('cfg.getvar_s(u"tree1.tree2.key12")', setup=setup, number=num)) | 101 print("expand-string-one-noncached: %.4f" % timeit.timeit('cfg.getvar_s(u"tree1.tree2.key12")', setup=setup, number=num)) |
| 95 print("-"*50) | 102 print("-"*50) |
| 96 | 103 |
| 97 if all or "expand-string-many" in opts: | 104 if all or "expand-string-many" in opts: |
| 98 print("expand-string-many: %.4f" % timeit.timeit('cfg.getvarl(u"tree1", u"tree2", "key10")', setup=setup, number=num)) | 105 print("expand-string-many: %.4f" % timeit.timeit('cfg.getvarl(u"tree1", u"tree2", "key10")', setup=setup, number=num)) |
| 99 print("expand-string-many: %.4f" % timeit.timeit('cfg.getvarl_s(u"tree1", u"tree2", "key10")', setup=setup, number=num)) | 106 print("expand-string-many: %.4f" % timeit.timeit('cfg.getvarl_s(u"tree1", u"tree2", "key10")', setup=setup, number=num)) |
| 100 print("expand-string-many: %.4f" % timeit.timeit('cfg.getvar(u"tree1.tree2.key10")', setup=setup, number=num)) | 107 print("expand-string-many: %.4f" % timeit.timeit('cfg.getvar(u"tree1.tree2.key10")', setup=setup, number=num)) |
| 104 if all or "expand-string-many-noncached" in opts: | 111 if all or "expand-string-many-noncached" in opts: |
| 105 print("expand-string-many-noncached: %.4f" % timeit.timeit('cfg.getvarl(u"tree1", u"tree2", u"key13")', setup=setup, number=num)) | 112 print("expand-string-many-noncached: %.4f" % timeit.timeit('cfg.getvarl(u"tree1", u"tree2", u"key13")', setup=setup, number=num)) |
| 106 print("expand-string-many-noncached: %.4f" % timeit.timeit('cfg.getvarl_s(u"tree1", u"tree2", u"key13")', setup=setup, number=num)) | 113 print("expand-string-many-noncached: %.4f" % timeit.timeit('cfg.getvarl_s(u"tree1", u"tree2", u"key13")', setup=setup, number=num)) |
| 107 print("expand-string-many-noncached: %.4f" % timeit.timeit('cfg.getvar(u"tree1.tree2.key13")', setup=setup, number=num)) | 114 print("expand-string-many-noncached: %.4f" % timeit.timeit('cfg.getvar(u"tree1.tree2.key13")', setup=setup, number=num)) |
| 108 print("expand-string-many-noncached: %.4f" % timeit.timeit('cfg.getvar_s(u"tree1.tree2.key13")', setup=setup, number=num)) | 115 print("expand-string-many-noncached: %.4f" % timeit.timeit('cfg.getvar_s(u"tree1.tree2.key13")', setup=setup, number=num)) |
| 109 print("-"*50) | 116 print("-"*50) |
| 110 | 117 |
| 111 if all or "expand-list" in opts: | 118 if all or "expand-list" in opts: |
| 112 print("expand-list: %.4f" % timeit.timeit('cfg.getvarl(u"tree1", u"tree2", "key8")', setup=setup, number=num)) | 119 print("expand-list: %.4f" % timeit.timeit('cfg.getvarl(u"tree1", u"tree2", "key8")', setup=setup, number=num)) |
| 113 print("expand-list: %.4f" % timeit.timeit('cfg.getvarl_s(u"tree1", u"tree2", "key8")', setup=setup, number=num)) | 120 print("expand-list: %.4f" % timeit.timeit('cfg.getvarl_s(u"tree1", u"tree2", "key8")', setup=setup, number=num)) |
| 114 print("expand-list: %.4f" % timeit.timeit('cfg.getvar(u"tree1.tree2.key8")', setup=setup, number=num)) | 121 print("expand-list: %.4f" % timeit.timeit('cfg.getvar(u"tree1.tree2.key8")', setup=setup, number=num)) |
