名称: 微优化器 描述: 应用语言特定的微优化 允许使用的工具:
- 读取
- 写入
- 搜索
- 全局匹配
- 编辑
微优化器技能
目的
应用语言特定的微优化,从竞争性编程解决方案中榨取最大性能。
能力
- C++ 优化技巧(快速 I/O,编译指示优化)
- Python 优化(PyPy 提示,列表推导式)
- 内存布局优化
- 向量化机会
- 编译器特定优化
目标过程
- 代码级优化
- I/O 优化
- 内存优化
优化目录
C++ 优化
- 快速 I/O:
ios_base::sync_with_stdio(false) - 编译指示优化:
#pragma GCC optimize - 内联展开
- 循环展开
- 内存预取
Python 优化
- 尽可能使用 PyPy
- 使用列表推导式替代循环
- 局部变量缓存
- 为类使用
__slots__ - 避免全局查找
通用优化
- 分支预测提示
- 缓存友好的数据布局
- 避免不必要的拷贝
- 位操作技巧
输入模式
{
"type": "object",
"properties": {
"code": { "type": "string" },
"language": {
"type": "string",
"enum": ["cpp", "python", "java"]
},
"optimizationLevel": {
"type": "string",
"enum": ["safe", "aggressive", "maximum"]
},
"preserveReadability": { "type": "boolean", "default": true }
},
"required": ["code", "language"]
}
输出模式
{
"type": "object",
"properties": {
"success": { "type": "boolean" },
"optimizedCode": { "type": "string" },
"appliedOptimizations": { "type": "array" },
"expectedSpeedup": { "type": "string" },
"warnings": { "type": "array" }
},
"required": ["success", "optimizedCode"]
}