Esempio n. 1
0
def main():
    if fat.get_specialized(func) or fat.get_specialized(func2):
        print("ERROR: functions already specialized!")
        sys.exit(1)

    fat.specialize(func2, fast_func2, [fat.GuardArgType(0, (list, ))])

    for range_pow10 in (0, 1, 3, 5):
        print("range(10 ** %s)" % range_pow10)

        dt = bench_list('func', range_pow10)
        print("- original bytecode: %s" % format_dt(dt))

        dt2 = bench_list('func2', range_pow10)
        print("- append=obj.append with guards: %s" % compared_dt(dt2, dt))

        dt2 = bench_list('fast_func2', range_pow10)
        print("- append=obj.append: %s" % compared_dt(dt2, dt))
def main():
    if fat.get_specialized(func) or fat.get_specialized(func2):
        print("ERROR: functions already specialized!")
        sys.exit(1)

    fat.specialize(func2, fast_func2, [fat.GuardArgType(0, (list,))])

    for range_pow10 in (0, 1, 3, 5):
        print("range(10 ** %s)" % range_pow10)

        dt = bench_list('func', range_pow10)
        print("- original bytecode: %s" % format_dt(dt))

        dt2 = bench_list('func2', range_pow10)
        print("- append=obj.append with guards: %s" % compared_dt(dt2, dt))

        dt2 = bench_list('fast_func2', range_pow10)
        print("- append=obj.append: %s" % compared_dt(dt2, dt))
Esempio n. 3
0
    """Test whether a path is absolute"""
    sep = _get_sep(s)
    return s.startswith(sep)

def fast_isabs(s):
    """Test whether a path is absolute"""
    sep = _get_sep(s)
    return s.startswith(sep)

# Manually inline _get_sep() in isabs() depending on the type of the s argument
def isabs_str(s):
    return s.startswith('/')

for func in (_get_sep, isabs, fast_isabs, isabs_str):
    if fat.get_specialized(func):
        print("ERROR: a function is already specialized!")
        sys.exit(1)

fat.specialize(fast_isabs, isabs_str,
               [fat.GuardArgType(0, (str,)),
                fat.GuardGlobals(('_get_sep',)),
                fat.GuardBuiltins(('isinstance',)),
                fat.GuardFunc(_get_sep)])

dt = bench("isabs('/abc')")
print("original isabs() bytecode: %s" % format_dt(dt))

dt2 = bench("fast_isabs('/abc')")
print("_get_sep() inlined in isabs(): %s" % compared_dt(dt2, dt))