File: test_statistics.py

package info (click to toggle)
pypy3 7.3.19%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 212,236 kB
  • sloc: python: 2,098,316; ansic: 540,565; sh: 21,462; asm: 14,419; cpp: 4,451; makefile: 4,209; objc: 761; xml: 530; exp: 499; javascript: 314; pascal: 244; lisp: 45; csh: 12; awk: 4
file content (32 lines) | stat: -rw-r--r-- 1,117 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from rpython.rtyper.lltypesystem import lltype
from rpython.memory.gctransform.test.test_transform import \
     rtype
from rpython.memory.gctransform.statistics import \
     relevant_gcvars_graph, relevant_gcvars, filter_for_nongcptr
from rpython.translator.translator import graphof

def test_count_vars_simple():
    S = lltype.GcStruct('abc', ('x', lltype.Signed))
    def f():
        s1 = lltype.malloc(S)
        s2 = lltype.malloc(S)
        s1.x = 1
        s2.x = 2
        return s1.x + s2.x
    t = rtype(f, [])
    assert relevant_gcvars_graph(graphof(t, f)) == [0, 1]

def test_count_vars_big():
    from rpython.translator.goal.targetrpystonex import make_target_definition
    from rpython.translator.backendopt.all import backend_optimizations
    entrypoint, _, _ = make_target_definition(10)
    t = rtype(entrypoint, [int])
    backend_optimizations(t)
    # does not crash
    rel = relevant_gcvars(t)
    print rel
    print sum(rel) / float(len(rel)), max(rel), min(rel)

    rel = relevant_gcvars(t, filter_for_nongcptr)
    print rel
    print sum(rel) / float(len(rel)), max(rel), min(rel)