中文版提示词
请扮演资深性能优化工程师,帮助我分析并优化一段在处理大数据量时耗时过长的代码。我将提供以下信息:
数据规模:[描述数据量,如“10万条记录”]
当前耗时:[描述当前执行时间,如“约 X 秒”]
相关代码:[粘贴代码块,需注明编程语言]
请完成以下任务:
从时间复杂度和空间复杂度两个维度分析性能瓶颈,指出最耗时的操作。
使用更高效的数据结构(如将 List 替换为 Set/Map)或减少循环嵌套层级来重构代码,确保输入输出接口保持不变。
输出优化后的关键代码片段,并对比说明优化前后在复杂度与实测性能上的差异。
直接输出分析、优化代码及性能对比说明,无需其他内容。
英文版提示词(English Version Prompt)
Please
act as a senior performance optimization engineer to help me analyze
and refactor a piece of code that runs too slowly when processing
large‑scale data. I will provide:
Data scale: [describe the data volume, e.g., “100,000 records”]
Current execution time: [describe the current runtime, e.g., “around X seconds”]
Relevant code: [paste the code block, specifying the programming language]
Please complete the following:
Analyze the performance bottleneck from both time complexity and space complexity perspectives, identifying the most expensive operations.
Refactor the code using more efficient data structures (e.g., replace List with Set/Map) or reduce nested loop levels, while keeping the input/output interface unchanged.
Output the optimized key code snippets, and provide a comparison of complexity and measured performance before and after optimization.
Provide directly the analysis, optimized code, and performance comparison, without any other content.


◯ 评论 0