到 2025 年,开发者不再会问如何使用 AI 工具进行编码,而是会问哪种 AI 最适合生成代码。由于市面上有众多性能卓越的模型,例如 Anthropic 的 Claude 4、OpenAI 的 GPT-4o 以及谷歌的 Gemini 2.5 Pro,AI 竞赛竞争异常激烈,我们也因此感到困惑不已。随着 AI 领域的不断发展,评估这些模型在代码生成方面的表现至关重要。在本文中,我们将比较 Claude 4 Sonnet、GPT-4o 和 Gemini 2.5 Pro 的编程能力和性能,以找出最佳的 AI 编码模型。
模型评估:Claude 4 vs GPT-4o vs Gemini 2.5 Pro
为了找到 2025 年最佳的 AI 编码模型,我们将首先根据架构、上下文窗口、定价和基准分数对 Claude 4 Sonnet、GPT-4o 和 Gemini 2.5 Pro 进行评估。
模型概述
这些模型均可通过云服务访问,并具备不同程度的多模态功能。在本节中,我们将探讨这三个模型的一些关键特性,并比较它们各自的优势。
功能特性 | Claude 4 | GPT-4o | Gemini 2.5 Pro |
---|---|---|---|
是否开源 | 否 | 否 | 否 |
发布日期 | 2025年5月22日 | 2024年5月 | 2025年5月6日 |
上下文窗口 | 200K | 128K | 1M+ |
API 提供商 | Anthropic API、AWS Bedrock、Google Vertex | OpenAI API、Azure OpenAI | Google Vertex AI、Google AI Studio |
支持的输入类型 | 文本、图像 | 文本、图像、音频、视频 | 文本、图像、音频、视频 |
价格比较
在当今人工智能时代,我们每个人都或多或少地使用这些模型。因此,模型价格是团队在构建大规模应用程序时需要考虑的重要因素之一,而 Claude 4 Opus 的输入和输出价格均位居所有模型之首。
模型 | 输入价格(每百万 token) | 输出价格(每百万 token) |
---|---|---|
Claude 4 | Opus:$15.00<br>Sonnet:$3.00 | Opus:$75.00<br>Sonnet:$15.00 |
GPT-4o | $5.00 | $20.00 |
Gemini 2.5 Pro | ≤200K:$1.25<br>>200K:$2.50 | ≤200K:$10.00<br>>200K:$15.00 |
基准测试比较
基准测试展示了模型在编码和推理等能力方面的性能。结果反映了该模型在代理编码、数学、推理和工具使用等数据上在不同领域的表现。
基准 | Claude 4 Opus | Claude 4 Sonnet | GPT-4o | Gemini 2.5 Pro |
---|---|---|---|---|
HumanEval(代码生成) | 不可用 | 不可用 | 74.8% | 75.6% |
GPQA(研究生推理) | 83.3% | 83.8% | 83.3% | 83.0% |
MMLU(世界知识) | 88.8% | 86.5% | 88.7% | 88.6% |
AIME 2025(数学) | 90.0% | 85.0% | 88.9% | 83.0% |
SWE-bench(代理编码) | 72.5% | 72.7% | 69.1% | 63.2% |
TAU-bench(工具使用) | 81.4% | 80.5% | 70.4% | 不可用 |
Terminal-bench(编码) | 43.2% | 35.5% | 30.2% | 25.3% |
MMMU(视觉推理) | 76.5% | 74.4% | 82.9% | 79.6% |
其中,Claude 4 在编码方面表现优异,GPT-4o 在推理方面表现优异,而 Gemini 2.5 Pro 则在不同模式下提供了强大且均衡的性能。更多信息,请访问此处。
总的来说
基于以上比较,我们对这些高级闭源模型的了解如下:
- 我们发现 Claude 4 在编码、数学和工具使用方面表现出色,但它也是最昂贵的。
- GPT-4o 擅长推理和多模态支持,能够处理不同的输入格式,使其成为更高级、更复杂的助手的理想选择。
- 同时,Gemini 2.5 Pro 凭借最大的上下文窗口和最具成本效益的价格,提供了强大而均衡的性能。
Claude 4 vs GPT-4o vs Gemini 2.5 Pro:编码能力
Claude 4 vs GPT-4o vs Gemini 2.5 Pro:编码能力
现在我们将比较 Claude 4、GPT-4o 和 Gemini 2.5 Pro 的代码编写能力。为此,我们将向这三个模型提供相同的提示,并根据以下指标评估它们的响应:
- 效率
- 可读性
- 注释和文档
- 错误处理
任务 1:使用 HTML、CSS 和 JS 设计扑克牌
提示词 : “Create an interactive webpage that displays a collection of WWE Superstar flashcards using HTML, CSS, and JavaScript. Each card should represent a WWE wrestler, and must include a front and back side. On the front, display the wrestler’s name and image. On the back, show additional stats such as their finishing move, brand, and championship titles. The flashcards should have a flip animation when hovered over or clicked.
Additionally, add interactive controls to make the page dynamic: a button that shuffles the cards, and another that shows a random card from the deck. The layout should be visually appealing and responsive for different screen sizes. Bonus points if you include sound effects like entrance music when a card is flipped.
Key Features to Implement:
- Front of card: wrestler’s name + image
- Back of card: stats (e.g., finisher, brand, titles)
- Flip animation using CSS or JS
- “Shuffle” button to randomly reorder cards
- “Show Random Superstar” button
- Responsive design.”
Claude 4 响应回复:
GPT-4o 响应回复:
Gemini 2.5 Pro 响应回复:
对比分析
在第一个任务中,Claude 4 提供了最具互动性的体验和最动态的视觉效果。它还在点击卡片时添加了音效。GPT-4o 提供了黑色主题布局,过渡流畅,按钮功能齐全,但缺乏音频功能。与此同时,Gemini 2.5 Pro 提供了最简单、最基本的顺序布局,没有动画或声音。此外,随机卡片功能未能正确显示卡片正面。总体而言,Claude 在这方面处于领先地位,其次是 GPT-4o,最后是 Gemini。
任务 2:构建一个小游戏
提示词: “Spell Strategy Game is a turn-based battle game built with Pygame, where two mages compete by casting spells from their spellbooks. Each player starts with 100 HP and 100 Mana and takes turns selecting spells that deal damage, heal, or apply special effects like shields and stuns. Spells consume mana and have cooldown periods, requiring players to manage resources and strategize carefully. The game features an engaging UI with health and mana bars, and spell cooldown indicators.. Players can face off against another human or an AI opponent, aiming to reduce their rival’s HP to zero through tactical decisions.
Key Features:
- Turn-based gameplay with two mages (PvP or PvAI)
- 100 HP and 100 Mana per player
- Spellbook with diverse spells: damage, healing, shields, stuns, mana recharge
- Mana costs and cooldowns for each spell to encourage strategic play
- Visual UI elements: health/mana bars, cooldown indicators, spell icons
- AI opponent with simple tactical decision-making
- Mouse-driven controls with optional keyboard shortcuts
- Clear in-game messaging showing actions and effects”
Claude 4 响应回复:
GPT-4o 响应回复:
Gemini 2.5 Pro 响应回复:
对比分析
在第二项任务中,总体而言,所有模型的图形质量均不理想。所有模型都呈现黑屏,界面简洁。然而,Claude 4 提供了最实用、最流畅的游戏操控,拥有丰富的攻击、防御和其他策略玩法。另一方面,GPT-4o 则存在性能问题,例如卡顿、窗口尺寸过小等。即使是 Gemini 2.5 Pro 也未能达到预期,其代码运行失败并出现一些错误。总体而言,Claude 再次领先,其次是 GPT-4o,最后是 Gemini 2.5 Pro。
任务3:买卖股票的最佳时机
提示词:“You are given an array prices where prices[i] is the price of a given stock on the ith day.Find the maximum profit you can achieve. You may complete at most two transactions.Note: You may not engage in multiple transactions simultaneously (i.e., you must sell the stock before you buy again).Example:Input: prices = [3,3,5,0,0,3,1,4]Output: 6Explanation: Buy on day 4 (price = 0) and sell on day 6 (price = 3), profit = 3-0 = 3. Then buy on day 7 (price = 1) and sell on day 8 (price = 4), profit = 4-1 = 3.”
Claude 4 响应回复:
GPT-4o 响应回复:
Gemini 2.5 Pro 响应回复:
比较分析
在第三个也是最后一个任务中,模型必须使用动态规划来解决问题。在这三个任务中,GPT-4o 提供了最实用且方法最完善的解决方案,它使用了一个简洁的二维动态规划,并进行了安全的初始化,同时还包含测试用例。虽然 Claude 4 提供了更详细、更具教育意义的方法,但其代码也较为冗长。与此同时,Gemini 2.5 Pro 提供了一种简洁的方法,但使用了 INT_MIN 初始化,这是一种风险较高的方法。因此,在这项任务中,GPT-4o 处于领先地位,其次是 Claude 4,最后是 Gemini 2.5 Pro。
最终结果
以下是对各模型在上述任务中表现的比较总结。
任务 | Claude 4 | GPT-4o | Gemini 2.5 Pro | 胜者 |
---|---|---|---|---|
任务 1(卡片 UI) | 最具互动性,带动画和音效 | 流畅的深色主题,带功能按钮,无音效 | 基本的顺序布局,卡片正面问题,无动画/音效 | Claude 4 |
任务 2(游戏控制) | 控制顺畅,策略选项广泛,功能最强 | 可用但延迟,小窗口 | 无法运行,界面错误 | Claude 4 |
任务 3(动态编程) | 冗长但具有教育意义,适合学习 | 干净且安全的动态规划解决方案,测试用例最多,最实用 | 简洁但不安全(使用 INT_MIN),缺乏稳健性 | GPT-4o |
To check the complete version of all the code files, please visit here.
要查看所有代码文件的完整版本,请访问此处。
小结
现在,通过对三个不同任务的全面比较,我们观察到 Claude 4 凭借其交互式 UI 设计能力和稳定的模块化编程逻辑脱颖而出,使其成为整体表现最佳的模型。而 GPT-4o 则以其简洁实用的代码紧随其后,并在算法问题解决方面表现出色。与此同时,Gemini 2.5 Pro 在 UI 设计和所有任务的执行稳定性方面均有所欠缺。但这些观察完全基于上述比较,每个模型都有其独特的优势,模型的选择完全取决于我们试图解决的问题。
评论留言