From 5362845635a18e80a156965dcd8d4a837fccb4a8 Mon Sep 17 00:00:00 2001 From: hjdhnx Date: Tue, 27 Sep 2022 10:54:49 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=80=A7=E8=83=BD=E5=AF=B9?= =?UTF-8?q?=E6=AF=94=E5=92=8C=E6=B5=8B=E8=AF=95=E6=A1=88=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- js/version.txt | 2 +- py/qkjs/quick.py | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/js/version.txt b/js/version.txt index 07dc2df..8fba550 100644 --- a/js/version.txt +++ b/js/version.txt @@ -1 +1 @@ -3.7.16 \ No newline at end of file +3.7.17 \ No newline at end of file diff --git a/py/qkjs/quick.py b/py/qkjs/quick.py index f53a315..fde2105 100644 --- a/py/qkjs/quick.py +++ b/py/qkjs/quick.py @@ -1,5 +1,7 @@ from quickjs import Function,Context import requests +from time import time +import js2py import json ctx = Context() ctx.add_callable("print", print) @@ -85,4 +87,40 @@ def request(url): ctx.add_callable('request',request) ctx.eval('bd()') +t1 = time() +with open('../../js/兔小贝.js',encoding='utf-8') as f1: + jscode = f1.read() + print(jscode) + +ctx1 = Context() +ctx1.eval(jscode) +ret = ctx1.get('rule') +print(type(ret.json()),ret.json()) +print(json.loads(ret.json())) +t2 = time() +print(f'quickjs耗时:{round((t2-t1)*1000,2)}毫秒') +tt1 = time() +ctx1.eval(jscode) +ret = ctx1.get('rule') +print(type(ret.json()),ret.json()) +print(json.loads(ret.json())) +tt2 = time() +print(f'quickjs第2次耗时:{round((tt2-tt1)*1000,2)}毫秒') + +t3 = time() +with open('../../js/兔小贝.js',encoding='utf-8') as f1: + jscode = f1.read() + print(jscode) +ctx2 = js2py.EvalJs({},enable_require=False) # enable_require启用require关键字,会自动获取系统nodejs环境 +ctx2.execute(jscode) +ret = ctx2.rule.to_dict() +print(type(ret),ret) +t4 = time() +print(f'js2py耗时:{round((t4-t3)*1000,2)}毫秒') +t5 = time() +ctx2.execute(jscode) +ret = ctx2.rule.to_dict() +print(type(ret),ret) +t6 = time() +print(f'js2py第2次耗时:{round((t6-t5)*1000,2)}毫秒') # 报错提示:(没法把python对象给qkjs,基础数据类型字典也不行,json等包更不行了) Unsupported type when converting a Python object to quickjs: dict. \ No newline at end of file -- GitLab