-
Notifications
You must be signed in to change notification settings - Fork 1
/
bench.mjs
42 lines (40 loc) · 1.38 KB
/
bench.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { readFile } from 'node:fs/promises';
import * as MarkovStrings from 'markov-strings';
import MarkovTypescript from 'markov-typescript';
import { Bench } from 'tinybench';
import { MultiStateMarkovChain as MultiStateKurwov } from './dist/index.mjs';
// replace the 10000 with the number of sentences you want to use for the benchmark
const data = (await readFile('data.txt', 'utf8')).split('\n').slice(0, 10000);
console.log('Data size:', data.length);
const bench = new Bench()
.add('kurwov', () => {
const chain = new Kurwov(data);
chain.generate();
})
.add('kurwov-multistate', () => {
const chain = new MultiStateKurwov(data, 2);
chain.generate();
})
.add('markov-typescript', () => {
const chain = new MarkovTypescript.MarkovChain(2);
for (const line of data) {
chain.learn(line.split(' '));
}
chain.walk().join(' ');
})
.add('markov-generator', () => {
const chain = new MarkovGen({
input: data,
minLength: 0,
});
chain.makeChain();
})
.add('markov-strings', () => {
const chain = new MarkovStrings.default.default(2);
chain.addData(data);
chain.generate();
});
await bench.warmup();
await bench.run();
console.table(bench.table());
// foswig, mrkv, markov-chains error as of 2024-08-23 so they're not included