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,32 +1,24 @@
|
||||
async function processCSV(csv, config) {
|
||||
const { parse } = await import('https://cdn.jsdelivr.net/npm/papaparse@5/+esm');
|
||||
const { filterColumn, filterValue, groupBy, aggregateColumn, operation } = config;
|
||||
|
||||
const { default: Papa } = await import('https://cdn.jsdelivr.net/npm/papaparse@5/+esm');
|
||||
|
||||
const { data } = Papa.parse(csv, { header: true, skipEmptyLines: true });
|
||||
const { data } = parse(csv, { header: true, skipEmptyLines: true });
|
||||
|
||||
const filtered = data.filter(row => row[filterColumn] == filterValue);
|
||||
|
||||
const groups = {};
|
||||
for (const row of filtered) {
|
||||
const key = row[groupBy];
|
||||
(groups[key] ??= []).push(row);
|
||||
(groups[key] ??= []).push(+row[aggregateColumn] || 0);
|
||||
}
|
||||
|
||||
const toNum = v => {
|
||||
const n = Number(v);
|
||||
return isNaN(n) ? 0 : n;
|
||||
};
|
||||
|
||||
const ops = {
|
||||
sum: rows => rows.reduce((s, r) => s + toNum(r[aggregateColumn]), 0),
|
||||
avg: rows => rows.length ? ops.sum(rows) / rows.length : 0,
|
||||
count: rows => rows.length
|
||||
};
|
||||
|
||||
return Object.entries(groups).map(([k, v]) => ({
|
||||
[groupBy]: k,
|
||||
result: ops[operation](v)
|
||||
return Object.entries(groups).map(([key, vals]) => ({
|
||||
[groupBy]: key,
|
||||
result: operation === 'count' ? vals.length :
|
||||
operation === 'sum' ? vals.reduce((a, b) => a + b, 0) :
|
||||
vals.reduce((a, b) => a + b, 0) / vals.length
|
||||
}));
|
||||
}
|
||||
export default processCSV;
|
||||
export default processCSV;
|
||||
// Generation time: 4.406s
|
||||
// Result: FAIL
|
||||
@@ -1,27 +1,28 @@
|
||||
const processCSV = async (csv, { filterColumn, filterValue, groupBy, aggregateColumn, operation }) => {
|
||||
const [{ default: Papa }] = await Promise.all([
|
||||
import('https://cdn.jsdelivr.net/npm/papaparse@5.4.1/+esm')
|
||||
]);
|
||||
|
||||
const { data } = Papa.parse(csv, { header: true, skipEmptyLines: true });
|
||||
async function processCSV(csv, config) {
|
||||
const { parse } = await import('https://cdn.jsdelivr.net/npm/papaparse@5.4.1/+esm');
|
||||
|
||||
const filtered = data.filter(row => row[filterColumn] == filterValue);
|
||||
const { data } = parse(csv, { header: true, skipEmptyLines: true });
|
||||
|
||||
const filtered = data.filter(row => row[config.filterColumn] == config.filterValue);
|
||||
|
||||
const groups = filtered.reduce((acc, row) => {
|
||||
const key = row[groupBy];
|
||||
if (!acc[key]) acc[key] = [];
|
||||
acc[key].push(row);
|
||||
const key = row[config.groupBy];
|
||||
(acc[key] ??= []).push(row);
|
||||
return acc;
|
||||
}, {});
|
||||
|
||||
|
||||
return Object.entries(groups).map(([key, rows]) => {
|
||||
const values = rows.map(r => Number(r[aggregateColumn]) || 0);
|
||||
const values = rows.map(r => Number(r[config.aggregateColumn]) || 0);
|
||||
const sum = values.reduce((a, b) => a + b, 0);
|
||||
|
||||
return {
|
||||
[groupBy]: key,
|
||||
result: operation === 'sum' ? sum : operation === 'avg' ? sum / values.length : values.length
|
||||
[config.groupBy]: key,
|
||||
result: config.operation === 'sum' ? sum :
|
||||
config.operation === 'avg' ? sum / values.length :
|
||||
values.length
|
||||
};
|
||||
});
|
||||
};
|
||||
export default processCSV;
|
||||
}
|
||||
export default processCSV;
|
||||
// Generation time: 4.238s
|
||||
// Result: FAIL
|
||||
@@ -1,34 +0,0 @@
|
||||
async function processCSV(csvString, config) {
|
||||
const {
|
||||
filterColumn: fc,
|
||||
filterValue: fv,
|
||||
groupBy: gb,
|
||||
aggregateColumn: ac,
|
||||
operation: op
|
||||
} = config;
|
||||
|
||||
const { default: Papa } = await import('https://cdn.jsdelivr.net/npm/papaparse@5.3.2/papaparse.min.js');
|
||||
|
||||
const { data } = Papa.parse(csvString, {
|
||||
header: true,
|
||||
skipEmptyLines: true
|
||||
});
|
||||
|
||||
const groups = data.reduce((acc, row) => {
|
||||
if (row[fc] == fv) {
|
||||
const key = row[gb];
|
||||
const val = Number(row[ac]) || 0;
|
||||
|
||||
acc[key] = acc[key] || { sum: 0, count: 0 };
|
||||
acc[key].sum += val;
|
||||
acc[key].count++;
|
||||
}
|
||||
return acc;
|
||||
}, {});
|
||||
|
||||
return Object.entries(groups).map(([key, { sum, count }]) => ({
|
||||
[gb]: key,
|
||||
result: op === 'avg' ? sum / count : op === 'sum' ? sum : count,
|
||||
}));
|
||||
}
|
||||
export default processCSV;
|
||||
@@ -1,19 +1,16 @@
|
||||
export const processCSV = async (csvString, { filterColumn, filterValue, groupBy, aggregateColumn, operation }) => {
|
||||
const [{ csvParse }, { rollup, sum, mean }] = await Promise.all([
|
||||
import('https://esm.sh/d3-dsv'),
|
||||
import('https://esm.sh/d3-array')
|
||||
]);
|
||||
|
||||
const getValue = d => +(d[aggregateColumn]) || 0;
|
||||
|
||||
const grouped = rollup(
|
||||
csvParse(csvString).filter(row => row[filterColumn] == filterValue),
|
||||
group => operation === 'count'
|
||||
? group.length
|
||||
: (operation === 'sum' ? sum : mean)(group, getValue),
|
||||
row => row[groupBy]
|
||||
);
|
||||
|
||||
return Array.from(grouped, ([key, result]) => ({ [groupBy]: key, result }));
|
||||
const processCSV = async (str, { filterColumn: fc, filterValue: fv, groupBy: gb, aggregateColumn: ac, operation: op }) => {
|
||||
const { csvParse, rollups, sum } = await import('https://esm.sh/d3@7');
|
||||
const num = v => +v || 0;
|
||||
return rollups(
|
||||
csvParse(str).filter(d => d[fc] == fv),
|
||||
g => {
|
||||
if (op === 'count') return g.length;
|
||||
const t = sum(g, d => num(d[ac]));
|
||||
return op === 'sum' ? t : t / g.length;
|
||||
},
|
||||
d => d[gb]
|
||||
).map(([k, v]) => ({ [gb]: k, result: v }));
|
||||
};
|
||||
export default processCSV;
|
||||
export default processCSV;
|
||||
// Generation time: 40.784s
|
||||
// Result: PASS
|
||||
@@ -1,2 +1,17 @@
|
||||
async function processCSV(csv,{filterColumn:f,filterValue:v,groupBy:g,aggregateColumn:a,operation:o}){const{default:P}=await import('https://cdn.jsdelivr.net/npm/papaparse@5.4.1/+esm');const{data}=P.parse(csv,{header:true});const grouped=data.filter(r=>r[f]==v).reduce((c,r)=>{const k=r[g],n=Number(r[a])||0;c[k]||=(c[k]={s:0,c:0});c[k].s+=n;c[k].c++;return c},{});return Object.entries(grouped).map(([k,{s,c}])=>({[g]:k,result:o=='sum'?s:o=='avg'?s/c:c}))}
|
||||
export default processCSV;
|
||||
async function processCSV(csv, { filterColumn: fc, filterValue: fv, groupBy: gb, aggregateColumn: ac, operation: op }) {
|
||||
const { default: Papa } = await import('https://cdn.jsdelivr.net/npm/papaparse@5.4.1/+esm');
|
||||
const groups = {};
|
||||
|
||||
Papa.parse(csv, { header: true }).data
|
||||
.filter(r => r[fc] == fv)
|
||||
.forEach(r => {
|
||||
const key = r[gb], g = groups[key] || (groups[key] = { c: 0, s: 0 });
|
||||
g.c++;
|
||||
g.s += +r[ac] || 0;
|
||||
});
|
||||
|
||||
return Object.entries(groups).map(([k, { c, s }]) => ({ [gb]: k, result: op === 'count' ? c : op === 'avg' ? s / c : s }));
|
||||
}
|
||||
export default processCSV;
|
||||
// Generation time: 66.769s
|
||||
// Result: PASS
|
||||
@@ -1,21 +1,16 @@
|
||||
const libCache={},load=u=>libCache[u]??=import(u);
|
||||
const store={},load=u=>store[u]??=import(u),csvLib='https://cdn.jsdelivr.net/npm/papaparse@5.4.1/+esm',dataLib='https://cdn.jsdelivr.net/npm/lodash-es@4.17.21/+esm',toNum=v=>{const n=Number(v);return Number.isFinite(n)?n:0};
|
||||
|
||||
async function processCSV(csv,cfg){
|
||||
const [{csvParse},{groupBy}]=await Promise.all([
|
||||
load('https://cdn.jsdelivr.net/npm/d3-dsv@3.0.1/+esm'),
|
||||
load('https://cdn.jsdelivr.net/npm/lodash-es@4.17.21/+esm')
|
||||
]);
|
||||
const {filterColumn:f,filterValue:v,groupBy:k,aggregateColumn:a,operation:o}=cfg;
|
||||
const rows=csvParse(csv).filter(r=>r[f]==v);
|
||||
const grouped=groupBy(rows,r=>r[k]);
|
||||
return Object.entries(grouped).map(([g,list])=>{
|
||||
const nums=list.map(r=>{
|
||||
const n=+r[a];
|
||||
return Number.isFinite(n)?n:0;
|
||||
});
|
||||
const sum=nums.reduce((s,n)=>s+n,0);
|
||||
const result=o==='count'?list.length:o==='sum'?sum:list.length?sum/list.length:0;
|
||||
return {[k]:g,result};
|
||||
async function processCSV(csv,opt){
|
||||
const [{Papa},{groupBy:gb}] = await Promise.all([load(csvLib),load(dataLib)]);
|
||||
const {filterColumn:f,filterValue:v,groupBy:g,aggregateColumn:a,operation:o}=opt;
|
||||
const rows=Papa.parse(csv,{header:true,skipEmptyLines:true}).data.filter(r=>r&&r[f]==v);
|
||||
const grouped=gb(rows,r=>r[g]);
|
||||
return Object.entries(grouped).map(([k,items])=>{
|
||||
const total=items.reduce((s,r)=>s+toNum(r[a]),0);
|
||||
const result=o==='count'?items.length:o==='sum'?total:items.length?total/items.length:0;
|
||||
return {[g]:k,result};
|
||||
});
|
||||
}
|
||||
export default processCSV;
|
||||
export default processCSV;
|
||||
// Generation time: 29.916s
|
||||
// Result: FAIL
|
||||
@@ -1,25 +0,0 @@
|
||||
const processCSV = async (csvData, config) => {
|
||||
const { parse } = await import('https://cdn.skypack.dev/papaparse@5.3.0')
|
||||
const { filterColumn, filterValue, groupBy, aggregateColumn, operation } = config
|
||||
const { data } = parse(csvData, { header: true })
|
||||
|
||||
const filtered = data.filter(row => row[filterColumn] == filterValue)
|
||||
const groups = filtered.reduce((acc, row) => {
|
||||
const key = row[groupBy]
|
||||
if (!acc[key]) acc[key] = []
|
||||
acc[key].push(row)
|
||||
return acc
|
||||
}, {})
|
||||
|
||||
return Object.entries(groups).map(([groupValue, rows]) => {
|
||||
const numbers = rows.map(row => +row[aggregateColumn] || 0)
|
||||
let result
|
||||
|
||||
if (operation === 'sum') result = numbers.reduce((a, b) => a + b, 0)
|
||||
if (operation === 'avg') result = numbers.reduce((a, b) => a + b, 0) / numbers.length
|
||||
if (operation === 'count') result = numbers.length
|
||||
|
||||
return { [groupBy]: groupValue, result }
|
||||
})
|
||||
}
|
||||
export default processCSV;
|
||||
@@ -1,17 +0,0 @@
|
||||
async function processCSV(csv,config){
|
||||
const Papa=(await import('https://cdn.skypack.dev/papaparse')).default;
|
||||
const parsed=Papa.parse(csv,{header:!0}).data;
|
||||
const{filterColumn:fc,filterValue:fv,groupBy:gb,aggregateColumn:ac,operation:op}=config;
|
||||
const filtered=parsed.filter(r=>r[fc]==fv);
|
||||
const groups=new Map;
|
||||
for(const r of filtered){
|
||||
const gv=r[gb];
|
||||
const v=Number(r[ac])||0;
|
||||
const g=groups.get(gv)||{sum:0,count:0};
|
||||
g.sum+=v;
|
||||
g.count++;
|
||||
groups.set(gv,g);
|
||||
}
|
||||
return Array.from(groups,(g,gv)=>(({[gb]:gv,result:op==='sum'?g.sum:op==='count'?g.count:g.sum/g.count})));
|
||||
}
|
||||
export default processCSV;
|
||||
@@ -1,15 +0,0 @@
|
||||
async function processCSV(csv, config) {
|
||||
const [{ default: Papa }, { aq, sum, mean, count }] = await Promise.all([
|
||||
import('https://cdn.skypack.dev/papaparse'),
|
||||
import('https://cdn.skypack.dev/arquero')
|
||||
]);
|
||||
const data = Papa.parse(csv, { header: true, skipEmptyLines: true }).data;
|
||||
const { filterColumn, filterValue, groupBy, aggregateColumn, operation } = config;
|
||||
let table = aq.from(data).filter(d => d[filterColumn] == filterValue);
|
||||
if (operation !== 'count') {
|
||||
table = table.derive({ [aggregateColumn]: d => Number(d[aggregateColumn]) || 0 });
|
||||
}
|
||||
const makeAgg = operation === 'count' ? count() : { sum: sum, avg: mean }[operation](aggregateColumn);
|
||||
return table.groupby(groupBy).rollup({ result: makeAgg }).objects();
|
||||
}
|
||||
export default processCSV;
|
||||
20
tests/6_csv_processor/outputs/x-ai_grok-4.js
Normal file
20
tests/6_csv_processor/outputs/x-ai_grok-4.js
Normal file
@@ -0,0 +1,20 @@
|
||||
async function processCSV(csvString, config) {
|
||||
const d3 = await import('https://unpkg.com/d3?module');
|
||||
const data = d3.csvParse(csvString);
|
||||
const filtered = data.filter(row => row[config.filterColumn] == config.filterValue);
|
||||
const grouped = d3.group(filtered, d => d[config.groupBy]);
|
||||
return [...grouped].map(([key, group]) => {
|
||||
const col = config.aggregateColumn;
|
||||
const vals = group.map(r => Number(r[col]) || 0);
|
||||
let result;
|
||||
switch (config.operation) {
|
||||
case 'sum': result = vals.reduce((a, b) => a + b, 0); break;
|
||||
case 'avg': result = vals.reduce((a, b) => a + b, 0) / vals.length; break;
|
||||
case 'count': result = group.length; break;
|
||||
}
|
||||
return { [config.groupBy]: key, result };
|
||||
});
|
||||
}
|
||||
export default processCSV;
|
||||
// Generation time: 34.010s
|
||||
// Result: PASS
|
||||
Reference in New Issue
Block a user