From 7701f3d8252e7471e962093c019d83033d791104 Mon Sep 17 00:00:00 2001 From: Koichi Nakamura Date: Wed, 29 Dec 2021 21:17:00 +0900 Subject: [PATCH] speed up python version using struct module --- others/planck.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/others/planck.py b/others/planck.py index 7c79973..5c03404 100644 --- a/others/planck.py +++ b/others/planck.py @@ -6,9 +6,9 @@ import os import sys import operator -import array import ctypes import platform +from struct import pack, unpack RUNTIME_NAME = "Python {}".format(platform.python_version()) COPYRIGHT = "Copyright (c) 2021 Koichi Nakamura " @@ -38,11 +38,14 @@ def aligned(n): def align(): write(HERE_CELL, aligned(read(HERE_CELL))) -def read(addr, signed=False): - return int.from_bytes(memory[addr:addr+CELL], 'little', signed=signed) +def readi(addr): + return unpack('