mirror of
https://github.com/multipleof4/lynchmark.git
synced 2026-01-14 00:27:55 +00:00
Docs: Update benchmark results
This commit is contained in:
@@ -1,29 +0,0 @@
|
||||
const processCSV = async (csv, config) => {
|
||||
const { parse } = await import('https://cdn.jsdelivr.net/npm/papaparse@5.4.1/+esm');
|
||||
|
||||
const { data } = parse(csv, { header: true, skipEmptyLines: true });
|
||||
|
||||
const filtered = data.filter(row =>
|
||||
String(row[config.filterColumn]).trim() === String(config.filterValue).trim()
|
||||
);
|
||||
|
||||
const grouped = filtered.reduce((acc, row) => {
|
||||
const key = row[config.groupBy];
|
||||
if (!acc[key]) acc[key] = [];
|
||||
acc[key].push(row);
|
||||
return acc;
|
||||
}, {});
|
||||
|
||||
const aggregate = (rows) => {
|
||||
const values = rows.map(r => parseFloat(r[config.aggregateColumn]) || 0);
|
||||
if (config.operation === 'sum') return values.reduce((a, b) => a + b, 0);
|
||||
if (config.operation === 'avg') return values.reduce((a, b) => a + b, 0) / values.length;
|
||||
return values.length;
|
||||
};
|
||||
|
||||
return Object.entries(grouped).map(([key, rows]) => ({
|
||||
[config.groupBy]: key,
|
||||
result: aggregate(rows)
|
||||
}));
|
||||
};
|
||||
export default processCSV;
|
||||
@@ -1,9 +1,15 @@
|
||||
const processCSV = async (csvString, config) => {
|
||||
const { parse } = await import('https://cdn.skypack.dev/papaparse');
|
||||
const { parse } = await import('https://cdn.jsdelivr.net/npm/papaparse@5.4.1/+esm');
|
||||
|
||||
const { data } = parse(csvString, { header: true, skipEmptyLines: true });
|
||||
const { data } = parse(csvString, {
|
||||
header: true,
|
||||
skipEmptyLines: true,
|
||||
dynamicTyping: true
|
||||
});
|
||||
|
||||
const filtered = data.filter(row => row[config.filterColumn] == config.filterValue);
|
||||
const filtered = data.filter(row =>
|
||||
row[config.filterColumn] == config.filterValue
|
||||
);
|
||||
|
||||
const grouped = filtered.reduce((acc, row) => {
|
||||
const key = row[config.groupBy];
|
||||
@@ -12,17 +18,15 @@ const processCSV = async (csvString, config) => {
|
||||
return acc;
|
||||
}, {});
|
||||
|
||||
return Object.entries(grouped).map(([key, rows]) => {
|
||||
let result;
|
||||
if (config.operation === 'count') {
|
||||
result = rows.length;
|
||||
} else {
|
||||
const values = rows.map(r => parseFloat(r[config.aggregateColumn]) || 0);
|
||||
result = config.operation === 'sum'
|
||||
? values.reduce((a, b) => a + b, 0)
|
||||
: values.reduce((a, b) => a + b, 0) / values.length;
|
||||
}
|
||||
return { [config.groupBy]: key, result };
|
||||
});
|
||||
const operations = {
|
||||
sum: arr => arr.reduce((s, r) => s + (Number(r[config.aggregateColumn]) || 0), 0),
|
||||
avg: arr => operations.sum(arr) / arr.length || 0,
|
||||
count: arr => arr.length
|
||||
};
|
||||
|
||||
return Object.entries(grouped).map(([key, rows]) => ({
|
||||
[config.groupBy]: key,
|
||||
result: operations[config.operation](rows)
|
||||
}));
|
||||
};
|
||||
export default processCSV;
|
||||
@@ -1,26 +0,0 @@
|
||||
async function processCSV(csv, config) {
|
||||
const { parse } = await import('https://esm.sh/papaparse@5.4.1');
|
||||
const { groupBy, sumBy, meanBy, countBy } = await import('https://esm.sh/lodash-es@4.17.21');
|
||||
|
||||
const { data } = parse(csv, { header: true, skipEmptyLines: true });
|
||||
|
||||
const filtered = data.filter(row =>
|
||||
String(row[config.filterColumn]) === String(config.filterValue)
|
||||
);
|
||||
|
||||
const grouped = Object.entries(
|
||||
groupBy(filtered, config.groupBy)
|
||||
);
|
||||
|
||||
const ops = {
|
||||
sum: arr => sumBy(arr, r => parseFloat(r[config.aggregateColumn]) || 0),
|
||||
avg: arr => meanBy(arr, r => parseFloat(r[config.aggregateColumn]) || 0),
|
||||
count: arr => arr.length
|
||||
};
|
||||
|
||||
return grouped.map(([key, rows]) => ({
|
||||
[config.groupBy]: key,
|
||||
result: ops[config.operation](rows)
|
||||
}));
|
||||
}
|
||||
export default processCSV;
|
||||
@@ -1,42 +0,0 @@
|
||||
const processCSV = async (
|
||||
csvString, {
|
||||
filterColumn,
|
||||
filterValue,
|
||||
groupBy,
|
||||
aggregateColumn,
|
||||
operation
|
||||
}
|
||||
) => {
|
||||
const [Papa, {
|
||||
default: _
|
||||
}] = await Promise.all([
|
||||
import('https://cdn.jsdelivr.net/npm/papaparse@5.4.1/papaparse.min.js'),
|
||||
import('https://cdn.jsdelivr.net/npm/lodash-es@4.17.21/+esm'),
|
||||
]);
|
||||
|
||||
const {
|
||||
data
|
||||
} = Papa.parse(csvString, {
|
||||
header: true,
|
||||
dynamicTyping: true,
|
||||
skipEmptyLines: true,
|
||||
});
|
||||
|
||||
const aggregators = {
|
||||
sum: g => _.sumBy(g, aggregateColumn),
|
||||
avg: g => _.meanBy(g, aggregateColumn),
|
||||
count: g => g.length,
|
||||
};
|
||||
|
||||
return _.chain(data)
|
||||
.filter({
|
||||
[filterColumn]: filterValue
|
||||
})
|
||||
.groupBy(groupBy)
|
||||
.map((rows, key) => ({
|
||||
[groupBy]: Number.isNaN(+key) ? key : +key,
|
||||
result: aggregators[operation](rows),
|
||||
}))
|
||||
.value();
|
||||
};
|
||||
export default processCSV;
|
||||
38
tests/6_csv_processor/outputs/google_gemini-2.5-pro.js
Normal file
38
tests/6_csv_processor/outputs/google_gemini-2.5-pro.js
Normal file
@@ -0,0 +1,38 @@
|
||||
const processCSV = async (csvString, config) => {
|
||||
const {
|
||||
filterColumn,
|
||||
filterValue,
|
||||
groupBy,
|
||||
aggregateColumn,
|
||||
operation,
|
||||
} = config;
|
||||
|
||||
const [Papa, _] = await Promise.all([
|
||||
import('https://cdn.jsdelivr.net/npm/papaparse@5.4.1/+esm'),
|
||||
import('https://cdn.jsdelivr.net/npm/lodash-es@4.17.21/+esm'),
|
||||
]);
|
||||
|
||||
const aggregators = {
|
||||
sum: items => _.sumBy(items, aggregateColumn),
|
||||
count: items => items.length,
|
||||
avg: items => _.sumBy(items, aggregateColumn) / items.length || 0,
|
||||
};
|
||||
|
||||
const { data } = await new Promise(resolve =>
|
||||
Papa.parse(csvString, {
|
||||
header: true,
|
||||
dynamicTyping: true,
|
||||
skipEmptyLines: true,
|
||||
complete: resolve,
|
||||
})
|
||||
);
|
||||
|
||||
const filteredData = data.filter(row => row[filterColumn] === filterValue);
|
||||
const groupedData = _.groupBy(filteredData, groupBy);
|
||||
|
||||
return Object.entries(groupedData).map(([key, group]) => ({
|
||||
[groupBy]: isNaN(Number(key)) ? key : Number(key),
|
||||
result: aggregators[operation](group),
|
||||
}));
|
||||
};
|
||||
export default processCSV;
|
||||
@@ -1,18 +0,0 @@
|
||||
let cache;
|
||||
const load=()=>cache||(cache=Promise.all([
|
||||
import('https://cdn.jsdelivr.net/npm/papaparse@5.4.1/papaparse.min.mjs'),
|
||||
import('https://cdn.jsdelivr.net/npm/d3-array@3/+esm')
|
||||
]));
|
||||
const processCSV=async(csv,cfg)=>{
|
||||
const[{default:Papa},{rollup}]=await load();
|
||||
const{filterColumn:f,filterValue:v,groupBy:g,aggregateColumn:a,operation:o}=cfg;
|
||||
const rows=Papa.parse(csv,{header:1,dynamicTyping:1,skipEmptyLines:1}).data.filter(r=>r[f]===v);
|
||||
if(!rows.length)return[];
|
||||
const map=rollup(rows,s=>{
|
||||
if(o==='count')return s.length;
|
||||
const t=s.reduce((p,c)=>p+(Number(c[a])||0),0);
|
||||
return o==='avg'?t/s.length:t;
|
||||
},r=>r[g]);
|
||||
return Array.from(map,([k,val])=>({[g]:k,result:val}));
|
||||
};
|
||||
export default processCSV;
|
||||
16
tests/6_csv_processor/outputs/openai_gpt-5.1-codex.js
Normal file
16
tests/6_csv_processor/outputs/openai_gpt-5.1-codex.js
Normal file
@@ -0,0 +1,16 @@
|
||||
export const processCSV=async(csv,cfg)=>{
|
||||
const [{parse},{groupBy,sumBy}]=await Promise.all([
|
||||
import('https://cdn.jsdelivr.net/npm/papaparse@5.4.1/+esm'),
|
||||
import('https://cdn.jsdelivr.net/npm/lodash-es@4.17.21/+esm')
|
||||
]);
|
||||
const {filterColumn:fc,filterValue:fv,groupBy:gb,aggregateColumn:ac,operation:op}=cfg;
|
||||
const rows=parse(csv,{header:!0,skipEmptyLines:!0}).data.filter(r=>r[fc]==fv);
|
||||
const grouped=groupBy(rows,r=>r[gb]);
|
||||
const agg=v=>{
|
||||
if(op=='count')return v.length;
|
||||
const total=sumBy(v,x=>+x[ac]||0);
|
||||
return op=='avg'&&v.length?total/v.length:total;
|
||||
};
|
||||
return Object.entries(grouped).map(([k,v])=>({[gb]:k,result:agg(v)}));
|
||||
};
|
||||
export default processCSV;
|
||||
@@ -1,35 +0,0 @@
|
||||
async function processCSV(csv, c) {
|
||||
if (typeof csv !== 'string') throw new TypeError('csv must be string')
|
||||
if (!c || typeof c !== 'object') throw new TypeError('config required')
|
||||
let { filterColumn, filterValue, groupBy, aggregateColumn, operation } = c
|
||||
if (!filterColumn || !groupBy || !operation) throw new Error('missing config')
|
||||
if (!['sum', 'avg', 'count'].includes(operation)) throw new Error('bad op')
|
||||
|
||||
const { parse } = await import('https://cdn.skypack.dev/papaparse@5.4.1')
|
||||
const _ = (await import('https://cdn.skypack.dev/lodash-es@4.17.21')).default
|
||||
|
||||
const { data, errors } = parse(csv, { header: true, dynamicTyping: true, skipEmptyLines: true })
|
||||
if (errors && errors.length) throw new Error('csv parse error')
|
||||
|
||||
const rows = _.filter(data, r => r && r[filterColumn] === filterValue)
|
||||
if (!rows.length) return []
|
||||
|
||||
const grouped = _.groupBy(rows, r => r[groupBy])
|
||||
const out = []
|
||||
|
||||
_.forOwn(grouped, (items, k) => {
|
||||
let result
|
||||
if (operation === 'count') {
|
||||
result = items.length
|
||||
} else {
|
||||
const nums = _.map(items, i => Number(i[aggregateColumn])).filter(v => Number.isFinite(v))
|
||||
if (!nums.length) return
|
||||
const sum = _.sum(nums)
|
||||
result = operation === 'sum' ? sum : sum / nums.length
|
||||
}
|
||||
out.push({ [groupBy]: k, result })
|
||||
})
|
||||
|
||||
return out
|
||||
}
|
||||
export default processCSV;
|
||||
Reference in New Issue
Block a user