2026-05-09 · benchmark
修復 cursor 分頁的 off-by-one bug — agentic 程式碼編輯對決
顯示 prompt
以下是一個 cursor 分頁的 Node.js handler:
```js
function paginate(items, cursor, limit = 20) {
const start = cursor ? items.findIndex(i => i.id === cursor) : 0;
return {
data: items.slice(start, start + limit),
next: items[start + limit]?.id ?? null,
};
}
```
它有個微妙的 off-by-one bug:當給定 cursor 時,第一個回傳的是 cursor 本身(應該是 cursor *之後* 的 item)。修復這個函式。保留同樣的 signature 與回傳形狀。只在 bug 處加單行 inline 註釋。回傳僅修正後的函式,不要前言。 | Model | Latency | 成本 | 評語 |
|---|---|---|---|
| claude-opus-4-7 | 2240ms | $0.011 | 勝 |
| gpt-5 | 1890ms | $0.009 | 勝 |
| gemini-3-pro | 2050ms | $0.007 | 平 |
| qwen3.6-35b-a3b-nvfp4 | 920ms | $0.001 | 勝 |
顯示回答
claude-opus-4-7
function paginate(items, cursor, limit = 20) {
const start = cursor ? items.findIndex(i => i.id === cursor) + 1 : 0; // bug fix: skip cursor itself
return {
data: items.slice(start, start + limit),
next: items[start + limit]?.id ?? null,
};
} gpt-5
function paginate(items, cursor, limit = 20) {
// bug fix: cursor item itself was being returned; advance past it
const start = cursor ? items.findIndex(i => i.id === cursor) + 1 : 0;
return {
data: items.slice(start, start + limit),
next: items[start + limit]?.id ?? null,
};
} gemini-3-pro
function paginate(items, cursor, limit = 20) {
let start = 0;
if (cursor) {
const idx = items.findIndex(i => i.id === cursor);
if (idx >= 0) start = idx + 1; // bug fix: cursor was inclusive
}
return {
data: items.slice(start, start + limit),
next: items[start + limit]?.id ?? null,
};
} qwen3.6-35b-a3b-nvfp4
function paginate(items, cursor, limit = 20) {
const start = cursor ? items.findIndex(i => i.id === cursor) + 1 : 0; // off-by-one fix
return {
data: items.slice(start, start + limit),
next: items[start + limit]?.id ?? null,
};
} 測試模型是否抓到 off-by-one(start 應為 findIndex(...) + 1),且不破壞 cursor=null 分支。延遲於 client-side 量測。成本依 2026 年 5 月公開定價。所有模型給予完全相同的 prompt。