Pyodide 环境中正常运行了。从日志可以看到:
测试结果分析
环境信息:
- ✅ Python 3.10.2
- ✅ Pyodide 0.22.1
- ✅ WebAssembly (Emscripten) 环境
- ✅ 所有测试都成功完成
性能数据:
- CPU性能:素数计算 0.022秒,浮点运算 0.764秒
- 内存性能:列表和字典操作正常
- 文件I/O:读写操作成功
- 字符串操作:处理正常
查看完整日志文件的方法
由于日志文件已经创建成功,你可以用以下几种方式查看完整内容:
方法1:直接读取日志文件
# 查看完整的日志文件内容
def view_full_log():log_file = "pyodide_performance.log"if os.path.exists(log_file):print(f"=== 完整日志文件内容 ===")with open(log_file, 'r', encoding='utf-8') as f:content = f.read()print(content)print(f"文件大小: {len(content)} 字符")else:print("日志文件不存在")view_full_log()
方法2:分页查看
# 分页查看日志(每页20行)
def view_log_paginated():log_file = "pyodide_performance.log"if not os.path.exists(log_file):print("日志文件不存在")returnwith open(log_file, 'r', encoding='utf-8') as f:lines = f.readlines()page_size = 20total_pages = (len(lines) + page_size - 1) // page_sizefor page in range(total_pages):start = page * page_sizeend = start + page_sizeprint(f"\n=== 第 {page + 1}/{total_pages} 页 ===")for line in lines[start:end]:print(line.rstrip())if page < total_pages - 1:input("按回车继续...") # 或者使用其他方式暂停# view_log_paginated()
方法3:关键信息提取
# 提取关键性能指标
def extract_performance_metrics():log_file = "pyodide_performance.log"if not os.path.exists(log_file):print("日志文件不存在")returnwith open(log_file, 'r', encoding='utf-8') as f:content = f.read()print("=== 关键性能指标 ===")# 提取CPU性能import recpu_patterns = {'素数计算': r'Prime calculation.*?: ([\d.]+) seconds','浮点运算': r'Float operations.*?: ([\d.]+) seconds','整数运算': r'Integer operations: ([\d.]+) seconds'}for name, pattern in cpu_patterns.items():match = re.search(pattern, content)if match:print(f"{name}: {match.group(1)} 秒")# 提取内存性能mem_pattern = r'List allocation.*?: ([\d.]+) seconds'match = re.search(mem_pattern, content)if match:print(f"内存分配: {match.group(1)} 秒")# 提取文件I/Oio_patterns = {'文件写入': r'File write.*?: ([\d.]+) seconds','文件读取': r'File read.*?: ([\d.]+) seconds'}for name, pattern in io_patterns.items():match = re.search(pattern, content)if match:print(f"{name}: {match.group(1)} 秒")extract_performance_metrics()
方法4:文件信息查看
# 查看文件详细信息
def show_file_info():log_file = "pyodide_performance.log"if os.path.exists(log_file):import datetimestat = os.stat(log_file)print("=== 日志文件信息 ===")print(f"文件名: {log_file}")print(f"完整路径: {os.path.abspath(log_file)}")print(f"文件大小: {stat.st_size} 字节")print(f"创建时间: {datetime.datetime.fromtimestamp(stat.st_ctime)}")print(f"修改时间: {datetime.datetime.fromtimestamp(stat.st_mtime)}")# 显示文件所在目录的其他文件print(f"\n当前目录文件列表:")for item in os.listdir('.'):if item.endswith('.log') or item.endswith('.txt'):size = os.path.getsize(item)print(f" {item} ({size} bytes)")else:print("日志文件不存在")show_file_info()
运行建议
运行这个来查看完整日志:
view_full_log()
=== 完整日志文件内容 ===
PYODIDE PERFORMANCE TEST REPORT
==================================================
Test started: 2025-11-12 10:41:37.206000
Environment: Pyodide/WebAssembly
==================================================SYSTEM INFORMATION
----------------------------------------
Python version: 3.10.2 (main, Jan 25 2023, 18:32:53) [Clang 16.0.0 (https://github.com/llvm/llvm-project dee009d3b5c71a340eb4ebb3cfb4
Platform: emscripten
Current directory: /home/pyodide
Available modules: 729 loaded
Pyodide version: 0.22.1
----------------------------------------CPU PERFORMANCE TEST
----------------------------------------
Prime calculation (up to 10,000): 0.023 seconds
Primes found: 1229
Float operations (1M): 0.721 seconds
Result: 341.632263
Integer operations: 0.000 seconds
Factorial mod result: 0
----------------------------------------MEMORY PERFORMANCE TEST
----------------------------------------
List allocation (100K items): 0.022 seconds
Dict allocation (100K items): 0.029 seconds
List memory usage: 400492 bytes
Dict memory usage: 3145780 bytes
----------------------------------------STRING OPERATIONS TEST
----------------------------------------
String concatenation (10K): 0.003 seconds
String processing: 0.005 seconds
Uppercase letters: 2000
Lowercase letters: 8000
----------------------------------------FILE I/O PERFORMANCE TEST
----------------------------------------
File write (10K lines): 0.006 seconds
File read (10K lines): 0.003 seconds
Lines read: 10000
File size: 598890 bytes
----------------------------------------==================================================
TEST SUMMARY
==================================================
Total duration: 0.82 seconds
Tests completed: 5
Test finished: 2025-11-12 10:41:38.025000文件大小: 1759 字符
或者运行这个来查看关键指标:
extract_performance_metrics()
=== 关键性能指标 ===
素数计算: 0.023 秒
浮点运算: 0.721 秒
整数运算: 0.000 秒
内存分配: 0.022 秒
文件写入: 0.006 秒
文件读取: 0.003 秒
现在你有了一个完全兼容 Pyodide 环境的性能测试程序,可以正常创建和查看日志文件了!