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() pyjion.enable_tracing() if pgc: pyjion.enable_pgc() print("Enabling PGC") else: pyjion.disable_pgc() print("Disabling PGC") print(f"Trying with Optimizations = {opt_level}") pyjion.set_optimization_level(opt_level) 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
def main(): pyjion.enable() for i in range(40, 44): start = time.time() result = fib(i) end = time.time() print("%f, fib(%d)=%d" % (end - start, result, i))
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()
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()
perm[:k + 1] = perm[k::-1] flips_count += 1 assert len( perm ) > 0, f"Invalid size after reverse slice assignment for {k}" k = perm[0] if flips_count > max_flips: max_flips = flips_count while r != n: perm1_ins(r, perm1_pop(0)) count[r] -= 1 if count[r] > 0: break r += 1 else: return max_flips if __name__ == "__main__": print("Fannkuch({1}) took {0} without Pyjion".format( timeit.repeat(fannkuch, repeat=5, number=1), DEFAULT_ARG)) try: pyjion.enable() print("Fannkuch({1}) took {0} with Pyjion".format( timeit.repeat(fannkuch, repeat=5, number=1), DEFAULT_ARG)) pyjion.disable() except: pyjion.dis.dis(fannkuch)
def setUp(self) -> None: pyjion.enable()
def __init__(self, application): pyjion.enable() self.application = application
def _set_pyjion(pyjion_state: bool): if pyjion_state: pyjion.enable() pyjion.config(pgc=False) else: pyjion.disable()
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE # 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")
def count_set_bits_test(): pyjion.enable() """ int countSetBits(int a) { int count = 0; while (a) { count++; a &= (a - 1); } return count } """ cpu = None cpu = CPU6502(cycle_limit=100_000, printActivity=False, enableBRK=False, logging=False, logFile='log.txt') # BEQ F0 # INC EE # DEC CE # AND 2D # JMP 4C # 0x4000 stores the number of bits # 0x0000 stores the numbers """ # Write out values in ZP table 0xA2, 0x00, # LDX 0 0xA0, 0x00, # LDY 0 0x96, 0x00, # STX,Y ZP 0x00 0xE8, # INX 0xC8, # INY 0xD0, 0xFA, # BNE -6 0xA9, 0x00, # LDA 0 0xA2, 0x00, # LDX 0 0xA0, 0x00, # LDY 0 0x8D, 0x00, 0x40, # STA ABS 0x4000 0xA9, 0xFF, # LDA 255 0x8D, 0x00, 0x50, # STA ABS 0x5000 # START 0xF0, 0x0F, # BEQ to re-write table code 0xEE, 0x00, 0x40, # INC ABS 0x4000 0xCE, 0x00, 0x50, # DEC ABS 0x5000 0x2D, 0x00, 0x50, # AND ABS 0x5000 0x8D, 0x00, 0x50, # STA ABS 0x5000 0x4C, 0x18, 0x80, # JMP ABS 0x8014 # Re-write out values in ZP table 0xA2, 0x00, # LDX 0 0xA0, 0x00, # LDY 0 0x96, 0x00, # STX,Y ZP 0x00 0xE8, # INX 0xC8, # INY 0xD0, 0xFA, # BNE -6 """ program = [ # Write out values in ZP table 0xA2, 0x00, # LDX 0 0xA0, 0x00, # LDY 0 0x96, 0x00, # STX,Y ZP 0x00 0xE8, # INX 0xC8, # INY 0xD0, 0xFA, # BNE -6 0xA9, 0x00, # LDA 0 0xA2, 0x01, # LDX 1 0xA0, 0x01, # LDY 1 0x8D, 0x00, 0x40, # STA ABS 0x4000 # LOAD NUMBER TO PROCESS 0xB5, 0x00, # LDA ZP,X -- 0x8013 0x8D, 0x00, 0x50, # STA ABS 0x5000 # START 0xF0, 0x0F, # BEQ to re-write table code 0xFE, 0x00, 0x40, # INC ABS,X 0x4000 0xDE, 0x00, 0x00, # DEC ABS,X 0x0000 0x3D, 0x00, 0x00, # AND ABS,X 0x0000 0x9D, 0x00, 0x00, # STA ABS,X 0x0000 0x4C, 0x13, 0x80, # JMP ABS 0x8013 # Re-write out values in ZP table 0xE8, # INX - Check to see if we've done all 255 slots 0xD0, 0xE7, # BNE BACK TO LOAD NUMBER TO PROCESS 0xA2, 0x00, # LDX 0 0xA0, 0x00, # LDY 0 0x96, 0x00, # STX,Y ZP 0x00 0xE8, # INX 0xC8, # INY 0xD0, 0xFA, # BNE -6 ] cpu.load_program(instructions=program, memoryAddress=0x8000, mainProgram=True) cpu.program_counter = 0x8000 cpu.execute() # cpu.print_log() cpu.memory_dump(startingAddress=0x0000, endingAddress=0x00FF, display_format='Dec', items_per_row=16) cpu.memory_dump(startingAddress=0x4000, endingAddress=0x40FF, display_format='Dec', items_per_row=16) cpu.print_benchmark_info()