Esempio n. 1
0
def main():
    parser = argparse.ArgumentParser(prog='pyjion',
                                     description='Python JIT Compiler')

    group = parser.add_mutually_exclusive_group(required=True)
    group.add_argument('script', help='script file', nargs='?')

    group.add_argument('-m',
                       action='store',
                       type=str,
                       dest="module",
                       help="Execute module")

    parser.add_argument('--graph',
                        action='store_true',
                        help='Enable instruction graph generation')

    parser.add_argument('--debug',
                        action='store_true',
                        help='Enable debuggable JIT methods')

    parser.add_argument('--no-pgc', action='store_true', help='Disable PGC')

    parser.add_argument('-o',
                        '--opt-level',
                        action='store',
                        type=int,
                        default=1,
                        help='Optimization level (default 1')

    args = parser.parse_args()

    pyjion.enable()

    pyjion.config(graph=args.graph,
                  debug=args.debug,
                  pgc=not args.no_pgc,
                  level=args.opt_level)

    if args.module:
        runpy.run_module(args.module)
    else:
        runpy.run_path(args.script)
    pyjion.disable()
Esempio n. 2
0
def pytest_runtest_call(item: pytest.Item) -> None:
    pyjion.enable()
    pyjion.config(level=int(item.config.option.opt_level))
    for mark in item.iter_markers():
        if mark.name == "graph":
            pyjion.config(graph=True)
    pyjion.config(debug=True)
    item.runtest()
    pyjion.disable()
    info = pyjion.info(item.function)
    if not info.compiled:
        warnings.warn("{0} did not compile ({1})".format(
            item.function, str(info.compile_result)))
    pyjion.config(graph=False)
    gc.collect()
Esempio n. 3
0
def main(input_file, opt_level, pgc):
    SAVEDCWD = os.getcwd()
    tests = []

    # Lifted from libregr.main
    regex = re.compile(r'\btest_[a-zA-Z0-9_]+\b')
    with open(os.path.join(SAVEDCWD, input_file)) as fp:
        for line in fp:
            line = line.split('#', 1)[0]
            line = line.strip()
            match = regex.search(line)
            if match is not None:
                tests.append(match.group())

    has_failures = False

    for test in tests:
        test_cases = unittest.defaultTestLoader.loadTestsFromName(
            f"test.{test}")
        print(f"Testing {test}")
        for case in test_cases:
            pyjion.enable()
            print(f"Trying with Optimizations = {opt_level}")
            pyjion.config(level=opt_level, pgc=pgc, graph=True)
            r = unittest.result.TestResult()
            case.run(r)
            if r.wasSuccessful():
                print(f"All tests in case successful.")
            else:
                print(f"Failures occurred.")
                has_failures = True

                for failedcase, reason in r.expectedFailures:
                    print(
                        f"---------------------------------------------------------------"
                    )
                    print(f"Test case {failedcase} was expected to fail:")
                    print(reason)
                    print(
                        f"---------------------------------------------------------------"
                    )

                for failedcase, reason in r.failures:
                    print(
                        f"---------------------------------------------------------------"
                    )
                    print(f"Test case {failedcase} failed:")
                    print(reason)
                    print(
                        f"---------------------------------------------------------------"
                    )

                for failedcase, reason in r.errors:
                    print(
                        f"---------------------------------------------------------------"
                    )
                    print(f"Test case {failedcase} failed with errors:")
                    print(reason)
                    print(
                        f"---------------------------------------------------------------"
                    )

            pyjion.disable()
            gc.collect()

    return has_failures
Esempio n. 4
0
 def _set_pyjion(pyjion_state: bool):
     if pyjion_state:
         pyjion.enable()
         pyjion.config(pgc=False)
     else:
         pyjion.disable()
Esempio n. 5
0
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
from __future__ import annotations

if __name__ == "__main__":
    try:
        import pyjion  # type: ignore

        pyjion.enable()  # type: ignore
        pyjion.config(threshold=30,
                      pgc=True,
                      level=2,
                      debug=False,
                      graph=False)  # type: ignore
        print("Running with pyjion")

    except ImportError:
        print("Running without pyjion")
        pass

    try:
        import uvloop  # type: ignore

        print("Running with uvloop")
        uvloop.install()  # type: ignore

    except ImportError:
Esempio n. 6
0
# 2016-10-10: Python 3.6 takes 380 ms
DEFAULT_SIZE = 100


def bench_django_template(size=100):
    template = Template("""<table>
{% for row in table %}
<tr>{% for col in row %}<td>{{ col|escape }}</td>{% endfor %}</tr>
{% endfor %}
</table>
    """)
    table = [range(size) for _ in range(size)]
    context = Context({"table": table})
    template.render(context)


if __name__ == "__main__":
    django.conf.settings.configure(TEMPLATES=[{
        'BACKEND':
        'django.template.backends.django.DjangoTemplates',
    }])
    django.setup()

    print("Django Template took {0} without Pyjion".format(
        timeit.repeat(bench_django_template, repeat=5, number=1)))
    pyjion.enable()
    pyjion.config(level=2)
    print("Django Template took {0} with Pyjion".format(
        timeit.repeat(bench_django_template, repeat=5, number=1)))
    pyjion.disable()
Esempio n. 7
0
            globals(),
            locals(),
        )
        if hasattr(i, "__benchmarks__"):
            for benchmark in i.__benchmarks__:
                func, desc, settings, repeat = benchmark
                with cProfile.Profile() as pr:
                    without_result = timeit.repeat(func,
                                                   repeat=repeat,
                                                   number=repeat)

                pr.dump_stats(profiles_out / f'{f.stem}_{desc}_without.pstat')

                with cProfile.Profile() as pr:
                    pyjion.enable()
                    pyjion.config(**settings, graph=True)
                    with_result = timeit.repeat(func,
                                                repeat=repeat,
                                                number=repeat)
                    pyjion.disable()
                    pr.dump_stats(profiles_out / f'{f.stem}_{desc}_with.pstat')

                with open(profiles_out / f'{f.stem}_{desc}.cil', 'w') as il:
                    with redirect_stdout(il):
                        pyjion.dis.dis(func)

                with open(graphs_out / f'{f.stem}.dot', 'w') as dot:
                    for k, attrib in i.__dict__.items():
                        if hasattr(attrib, "__code__"):
                            if pyjion.info(attrib.__code__).failed:
                                warnings.warn(
Esempio n. 8
0
import pyjion
import gc
from test.libregrtest import main

pyjion.enable()
pyjion.config(graph=True, level=1, debug=True, pgc=True)
main()
pyjion.disable()
gc.collect()