mirror of
https://github.com/multipleof4/lynchmark.git
synced 2026-01-14 08:37:56 +00:00
Docs: Update benchmark results
This commit is contained in:
@@ -1,23 +1,26 @@
|
||||
const processCSV = async (csvString, { filterColumn, filterValue, groupBy, aggregateColumn, operation }) => {
|
||||
const { default: Papa } = await import('https://cdn.jsdelivr.net/npm/[email protected]/+esm');
|
||||
|
||||
const { data } = Papa.parse(csvString, { header: true, skipEmptyLines: true });
|
||||
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 });
|
||||
|
||||
const filtered = data.filter(row => row[filterColumn] == filterValue);
|
||||
|
||||
const groups = filtered.reduce((acc, row) => {
|
||||
const key = row[groupBy];
|
||||
(acc[key] ??= []).push(row);
|
||||
if (!acc[key]) acc[key] = [];
|
||||
acc[key].push(row);
|
||||
return acc;
|
||||
}, {});
|
||||
|
||||
|
||||
return Object.entries(groups).map(([key, rows]) => {
|
||||
const values = rows.map(r => +r[aggregateColumn] || 0);
|
||||
const values = rows.map(r => Number(r[aggregateColumn]) || 0);
|
||||
const sum = values.reduce((a, b) => a + b, 0);
|
||||
|
||||
return {
|
||||
[groupBy]: key,
|
||||
result: operation === 'sum' ? sum : operation === 'avg' ? sum / values.length : rows.length
|
||||
result: operation === 'sum' ? sum : operation === 'avg' ? sum / values.length : values.length
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
@@ -1,38 +1,34 @@
|
||||
async function processCSV(csvString, config) {
|
||||
const {
|
||||
filterColumn,
|
||||
filterValue,
|
||||
groupBy,
|
||||
aggregateColumn,
|
||||
operation
|
||||
filterColumn: fc,
|
||||
filterValue: fv,
|
||||
groupBy: gb,
|
||||
aggregateColumn: ac,
|
||||
operation: op
|
||||
} = config;
|
||||
|
||||
const { default: Papa } = await import('https://cdn.jsdelivr.net/npm/papaparse@5.4.1/+esm');
|
||||
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
|
||||
.filter(row => row[filterColumn] == filterValue)
|
||||
.reduce((acc, row) => {
|
||||
const key = row[groupBy];
|
||||
const val = Number(row[aggregateColumn]) || 0;
|
||||
const groups = data.reduce((acc, row) => {
|
||||
if (row[fc] == fv) {
|
||||
const key = row[gb];
|
||||
const val = Number(row[ac]) || 0;
|
||||
|
||||
if (operation === 'avg') {
|
||||
const group = (acc[key] ??= { sum: 0, count: 0 });
|
||||
group.sum += val;
|
||||
group.count++;
|
||||
} else {
|
||||
acc[key] = (acc[key] ?? 0) + (operation === 'sum' ? val : 1);
|
||||
}
|
||||
return acc;
|
||||
}, {});
|
||||
acc[key] = acc[key] || { sum: 0, count: 0 };
|
||||
acc[key].sum += val;
|
||||
acc[key].count++;
|
||||
}
|
||||
return acc;
|
||||
}, {});
|
||||
|
||||
return Object.entries(groups).map(([groupValue, aggData]) => ({
|
||||
[groupBy]: groupValue,
|
||||
result: operation === 'avg' ? aggData.sum / aggData.count : aggData,
|
||||
return Object.entries(groups).map(([key, { sum, count }]) => ({
|
||||
[gb]: key,
|
||||
result: op === 'avg' ? sum / count : op === 'sum' ? sum : count,
|
||||
}));
|
||||
}
|
||||
export default processCSV;
|
||||
@@ -0,0 +1,19 @@
|
||||
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 }));
|
||||
};
|
||||
export default processCSV;
|
||||
@@ -1,22 +0,0 @@
|
||||
const processCSV = async (csv, { filterColumn: fKey, filterValue: fVal, groupBy: gKey, aggregateColumn: aKey, operation: op }) => {
|
||||
const { parse } = await import('https://cdn.jsdelivr.net/npm/papaparse@5.4.1/+esm')
|
||||
const { data } = parse(csv, { header: true, skipEmptyLines: true })
|
||||
|
||||
const groups = data.reduce((acc, row) => {
|
||||
if (row[fKey] == fVal) {
|
||||
const key = row[gKey]
|
||||
const val = +row[aKey] || 0
|
||||
const rec = acc[key] || { sum: 0, count: 0 }
|
||||
rec.sum += val
|
||||
rec.count++
|
||||
acc[key] = rec
|
||||
}
|
||||
return acc
|
||||
}, {})
|
||||
|
||||
return Object.entries(groups).map(([key, { sum, count }]) => ({
|
||||
[gKey]: key,
|
||||
result: op === 'count' ? count : op === 'avg' ? sum / count : sum
|
||||
}))
|
||||
}
|
||||
export default processCSV;
|
||||
@@ -1,15 +1,2 @@
|
||||
async function processCSV(csv, { filterColumn:f, filterValue:v, groupBy:g, aggregateColumn:a, operation:o }) {
|
||||
const [{ default: Papa }, { default: _ }] = await Promise.all([
|
||||
import('https://cdn.jsdelivr.net/npm/papaparse@5.4.1/+esm'),
|
||||
import('https://cdn.jsdelivr.net/npm/lodash@4.17.21/+esm')
|
||||
]);
|
||||
|
||||
const data = Papa.parse(csv, { header:true, dynamicTyping:true }).data.filter(r => r[f] == v);
|
||||
|
||||
return Object.entries(_.groupBy(data, g)).map(([k, d]) => {
|
||||
const n = d.map(r => (x = Number(r[a]), isNaN(x) ? 0 : x));
|
||||
const s = n.reduce((p, c) => p + c, 0);
|
||||
return { [g]: k, result: o === 'count' ? d.length : o === 'avg' ? s / n.length : s };
|
||||
});
|
||||
}
|
||||
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;
|
||||
@@ -1,20 +1,21 @@
|
||||
const libCache={},load=u=>libCache[u]??=import(u);
|
||||
|
||||
async function processCSV(csv,cfg){
|
||||
const[{default:Papa},{groupBy}]=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:f,filterValue:v,groupBy:g,aggregateColumn:a,operation:o}=cfg;
|
||||
const rows=Papa.parse(csv,{header:true,skipEmptyLines:true}).data.filter(r=>r[f]==v);
|
||||
const groups=groupBy(rows,r=>r[g]);
|
||||
return Object.entries(groups).map(([k,list])=>{
|
||||
const nums=list.map(r=>{
|
||||
const n=Number(r[a]);
|
||||
return Number.isFinite(n)?n:0;
|
||||
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};
|
||||
});
|
||||
const sum=nums.reduce((t,n)=>t+n,0);
|
||||
const count=list.length;
|
||||
const result=o==='sum'?sum:o==='avg'?sum/count:count;
|
||||
return{[g]:k,result};
|
||||
});
|
||||
}
|
||||
export default processCSV;
|
||||
@@ -1,27 +1,17 @@
|
||||
async function processCSV(csv,{filterColumn,filterValue,groupBy,aggregateColumn,operation}){
|
||||
const Papa=(await import('https://cdn.jsdelivr.net/npm/papaparse@5/+esm')).default;
|
||||
const{data}=Papa.parse(csv,{header:true,skipEmptyLines:true});
|
||||
const groups=new Map();
|
||||
for(const row of data){
|
||||
if(row[filterColumn]==filterValue){
|
||||
const key=row[groupBy];
|
||||
const val=Number(row[aggregateColumn])||0;
|
||||
const g=groups.get(key)||{sum:0,count:0};
|
||||
g.sum+=val;
|
||||
g.count++;
|
||||
groups.set(key,g);
|
||||
}
|
||||
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);
|
||||
}
|
||||
const result=[];
|
||||
for(const[key,g]of groups){
|
||||
let res;
|
||||
switch(operation){
|
||||
case'sum':res=g.sum;break;
|
||||
case'avg':res=g.sum/g.count;break;
|
||||
case'count':res=g.count;break;
|
||||
}
|
||||
result.push({[groupBy]:key,result:res});
|
||||
}
|
||||
return result;
|
||||
return Array.from(groups,(g,gv)=>(({[gb]:gv,result:op==='sum'?g.sum:op==='count'?g.count:g.sum/g.count})));
|
||||
}
|
||||
export default processCSV;
|
||||
Reference in New Issue
Block a user