diff options
author | Guido van Rossum <guido@python.org> | 2023-12-12 21:43:08 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-12 21:43:08 (GMT) |
commit | 7316dfb0ebc46aedf484c1f15f03a0a309d12a42 (patch) | |
tree | 92f0fb1befd424b1235b61e9d0d0e1d0389c190b /Lib/test/test_capi/test_misc.py | |
parent | dfaa9e060bf6d69cb862a2ac140b8fccbebf3000 (diff) | |
download | cpython-7316dfb0ebc46aedf484c1f15f03a0a309d12a42.zip cpython-7316dfb0ebc46aedf484c1f15f03a0a309d12a42.tar.gz cpython-7316dfb0ebc46aedf484c1f15f03a0a309d12a42.tar.bz2 |
gh-112320: Implement on-trace confidence tracking for branches (#112321)
We track the confidence as a scaled int.
Diffstat (limited to 'Lib/test/test_capi/test_misc.py')
-rw-r--r-- | Lib/test/test_capi/test_misc.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/Lib/test/test_capi/test_misc.py b/Lib/test/test_capi/test_misc.py index e6b532e..776ee91 100644 --- a/Lib/test/test_capi/test_misc.py +++ b/Lib/test/test_capi/test_misc.py @@ -2985,6 +2985,37 @@ class TestUops(unittest.TestCase): uops = {opname for opname, _, _ in ex} self.assertIn("_FOR_ITER_TIER_TWO", uops) + def test_confidence_score(self): + def testfunc(n): + bits = 0 + for i in range(n): + if i & 0x01: + bits += 1 + if i & 0x02: + bits += 1 + if i&0x04: + bits += 1 + if i&0x08: + bits += 1 + if i&0x10: + bits += 1 + if i&0x20: + bits += 1 + return bits + + opt = _testinternalcapi.get_uop_optimizer() + with temporary_optimizer(opt): + x = testfunc(20) + + self.assertEqual(x, 40) + ex = get_first_executor(testfunc) + self.assertIsNotNone(ex) + ops = [opname for opname, _, _ in ex] + count = ops.count("_GUARD_IS_TRUE_POP") + # Because Each 'if' halves the score, the second branch is + # too much already. + self.assertEqual(count, 1) + @unittest.skipUnless(support.Py_GIL_DISABLED, 'need Py_GIL_DISABLED') class TestPyThreadId(unittest.TestCase): |