Skip to content

Commit ece13ca

Browse files
update test
1 parent 84c5eb0 commit ece13ca

1 file changed

Lines changed: 48 additions & 16 deletions

File tree

tests/perf.spec.ts

Lines changed: 48 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
// @ts-ignore
12
import * as util from 'util';
3+
24
import { IPredicate, Node, Predicate, Property, TransactionBuilder, Uid } from '../src';
35

46
describe('Performance testing', () => {
@@ -76,37 +78,67 @@ describe('Performance testing', () => {
7678
});
7779

7880
it.only('Fuzz with random data', () => {
81+
interface IStation {
82+
uid: string;
83+
name: string;
84+
connects: IStation[];
85+
}
86+
7987
@Node()
88+
// @ts-ignore
8089
class Station {
8190
@Uid()
8291
uid: string;
8392

84-
@Property()
93+
@Property({ name: 'name' })
8594
name: string;
8695

87-
@Predicate({ type: () => Station })
96+
@Predicate({ name: 'connects', type: () => Station })
8897
connects: IPredicate<Station>;
8998
}
9099

91-
const STATION_COUNT = 5;
100+
const MIN_DEPTH = 3;
101+
const CONNECTION_PER_STATION = 2;
102+
const STATION_COUNT = 50;
92103

93-
const allStations = new Array(STATION_COUNT).fill(null).map((_, idx) => ({
104+
console.time('Data create');
105+
const allStations: IStation[] = new Array(STATION_COUNT).fill(null).map((_, idx) => ({
94106
uid: `${idx}`,
95107
name: `Station_${idx}`,
96-
stations: [] as any[]
108+
connects: [] as any[]
97109
}));
98110

99-
new Array(2).fill(null).forEach(() => {
100-
const rand = Math.floor(Math.random() * STATION_COUNT);
101-
allStations.forEach(station => station.stations.push(allStations[rand]));
111+
new Array(MIN_DEPTH).fill(null).forEach(() => {
112+
allStations.forEach((station, idx) => {
113+
new Array(CONNECTION_PER_STATION).fill(null).forEach(() => {
114+
let rand = Math.floor(Math.random() * STATION_COUNT);
115+
if (rand !== idx) {
116+
station.connects.push(allStations[rand]);
117+
}
118+
});
119+
});
102120
});
103-
104-
console.log(util.inspect(allStations, { colors: true, depth: 10 }));
105-
106-
const result = TransactionBuilder.of(Station)
107-
.setRoot(allStations)
108-
.build();
109-
110-
console.log(util.inspect(result.tree, { colors: true, depth: 10 }));
121+
// console.timeEnd('Data create');
122+
// console.log(util.inspect(allStations, { colors: true, depth: 10, compact: true, breakLength: 200 }));
123+
124+
console.time('Data clean');
125+
const tb = TransactionBuilder.of(Station);
126+
tb.setRoot(allStations);
127+
console.timeEnd('Data clean');
128+
129+
// console.time('Map build');
130+
// tb.build();
131+
// console.timeEnd('Map build');
132+
// console.log(util.inspect(result.tree, { colors: true, depth: 20 }));
133+
// console.log(`Stations ${result.tree[0].name} connects to:\n`, result.tree[0].connects.get());
134+
135+
// expect(allStations[0].connects[0].connects[0].connects[0].connects[0].connects[0].uid).toEqual(
136+
// result.tree[0].connects
137+
// .get()[0]
138+
// .connects.get()[0]
139+
// .connects.get()[0]
140+
// .connects.get()[0]
141+
// .connects.get()[0].uid
142+
// );
111143
});
112144
});

0 commit comments

Comments
 (0)