Skip to content

Commit

Permalink
chore: basic benchmarks back
Browse files Browse the repository at this point in the history
  • Loading branch information
maraisr committed Sep 4, 2024
1 parent 74cf4b7 commit f9ef740
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
23 changes: 23 additions & 0 deletions lib/cache.bench.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import DataLoader from 'npm:dataloader';

import type { LoadFn } from './mod.ts';
import * as dldr from './cache.ts';

const loadFn: LoadFn<any, string> = async (keys: string[]) => Promise.resolve(keys);
const keys = ['a', 'b', 'c', 'a'];

Deno.bench({
name: 'dldr',
baseline: true,
async fn() {
let _ = await Promise.all(keys.map((key) => dldr.load(loadFn, undefined, key)));
},
});

Deno.bench({
name: 'dataloader',
async fn() {
const loader = new DataLoader(loadFn as any, { cache: true });
let _ = await loader.loadMany(keys);
},
});
22 changes: 22 additions & 0 deletions lib/mod.bench.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import DataLoader from 'npm:dataloader';

import * as dldr from './mod.ts';

const loadFn: dldr.LoadFn<any, string> = async (keys: string[]) => Promise.resolve(keys);
const keys = ['a', 'b', 'c', 'a'];

Deno.bench({
name: 'dldr',
baseline: true,
async fn() {
let _ = await Promise.all(keys.map((key) => dldr.load(loadFn, key)));
},
});

Deno.bench({
name: 'dataloader',
async fn() {
const loader = new DataLoader(loadFn as any, { cache: false });
let _ = await loader.loadMany(keys);
},
});

0 comments on commit f9ef740

Please sign in to comment.