Example #1
0
def test_tick():
    jc = JitCounter()
    jc._tick_slowpath = "not callable in this test!"
    incr = jc.compute_threshold(4)
    for i in range(5):
        r = jc.tick(index2hash(jc, 104), incr)
        assert r is (i == 3)
    for i in range(5):
        r = jc.tick(index2hash(jc, 108), incr)
        s = jc.tick(index2hash(jc, 109), incr)
        assert r is (i == 3)
        assert s is (i == 3)
    jc.reset(index2hash(jc, 108))
    for i in range(5):
        r = jc.tick(index2hash(jc, 108), incr)
        assert r is (i == 3)
Example #2
0
def test_tick():
    jc = JitCounter()
    jc._tick_slowpath = "not callable in this test!"
    incr = jc.compute_threshold(4)
    for i in range(5):
        r = jc.tick(index2hash(jc, 104), incr)
        assert r is (i == 3)
    for i in range(5):
        r = jc.tick(index2hash(jc, 108), incr)
        s = jc.tick(index2hash(jc, 109), incr)
        assert r is (i == 3)
        assert s is (i == 3)
    jc.reset(index2hash(jc, 108))
    for i in range(5):
        r = jc.tick(index2hash(jc, 108), incr)
        assert r is (i == 3)
Example #3
0
def test_collisions():
    jc = JitCounter(size=4)     # 2 bits
    incr = jc.compute_threshold(4)
    for i in range(5):
        for sk in range(100, 105):
            r = jc.tick(index2hash(jc, 3, subhash=sk), incr)
            assert r is (i == 3)

    jc = JitCounter()
    incr = jc.compute_threshold(4)
    misses = 0
    for i in range(5):
        for sk in range(100, 106):
            r = jc.tick(index2hash(jc, 3, subhash=sk), incr)
            if r:
                assert i == 3
            elif i == 3:
                misses += 1
    assert misses < 5
Example #4
0
def test_collisions():
    jc = JitCounter(size=4)  # 2 bits
    incr = jc.compute_threshold(4)
    for i in range(5):
        for sk in range(100, 105):
            r = jc.tick(index2hash(jc, 3, subhash=sk), incr)
            assert r is (i == 3)

    jc = JitCounter()
    incr = jc.compute_threshold(4)
    misses = 0
    for i in range(5):
        for sk in range(100, 106):
            r = jc.tick(index2hash(jc, 3, subhash=sk), incr)
            if r:
                assert i == 3
            elif i == 3:
                misses += 1
    assert misses < 5
Example #5
0
def test_change_current_fraction():
    jc = JitCounter()
    incr = jc.compute_threshold(8)
    # change_current_fraction() with a fresh new hash
    jc.change_current_fraction(index2hash(jc, 104), 0.95)
    r = jc.tick(index2hash(jc, 104), incr)
    assert r is True
    # change_current_fraction() with an already-existing hash
    r = jc.tick(index2hash(jc, 104), incr)
    assert r is False
    jc.change_current_fraction(index2hash(jc, 104), 0.95)
    r = jc.tick(index2hash(jc, 104), incr)
    assert r is True
    # change_current_fraction() with a smaller incr
    incr = jc.compute_threshold(32)
    jc.change_current_fraction(index2hash(jc, 104), 0.95)
    r = jc.tick(index2hash(jc, 104), incr)
    assert r is False
    r = jc.tick(index2hash(jc, 104), incr)
    assert r is True
Example #6
0
def test_change_current_fraction():
    jc = JitCounter()
    incr = jc.compute_threshold(8)
    # change_current_fraction() with a fresh new hash
    jc.change_current_fraction(index2hash(jc, 104), 0.95)
    r = jc.tick(index2hash(jc, 104), incr)
    assert r is True
    # change_current_fraction() with an already-existing hash
    r = jc.tick(index2hash(jc, 104), incr)
    assert r is False
    jc.change_current_fraction(index2hash(jc, 104), 0.95)
    r = jc.tick(index2hash(jc, 104), incr)
    assert r is True
    # change_current_fraction() with a smaller incr
    incr = jc.compute_threshold(32)
    jc.change_current_fraction(index2hash(jc, 104), 0.95)
    r = jc.tick(index2hash(jc, 104), incr)
    assert r is False
    r = jc.tick(index2hash(jc, 104), incr)
    assert r is True