|
1 | | -import { IPredicate, Node, Predicate, TransactionBuilder, Uid } from '../src'; |
| 1 | +import * as util from 'util'; |
| 2 | +import { IPredicate, Node, Predicate, Property, TransactionBuilder, Uid } from '../src'; |
2 | 3 |
|
3 | | -it('performance Testing', () => { |
4 | | - @Node() |
5 | | - class Cell { |
6 | | - @Uid() |
7 | | - uid: string; |
| 4 | +describe('Performance testing', () => { |
| 5 | + it('mutation string generate', () => { |
| 6 | + @Node() |
| 7 | + class Cell { |
| 8 | + @Uid() |
| 9 | + uid: string; |
8 | 10 |
|
9 | | - @Predicate({ name: 'from_row', type: () => Row }) |
10 | | - fromRow: IPredicate<Row>; |
| 11 | + @Predicate({ name: 'from_row', type: () => Row }) |
| 12 | + fromRow: IPredicate<Row>; |
11 | 13 |
|
12 | | - @Predicate({ name: 'from_column', type: () => Column }) |
13 | | - fromColumn: IPredicate<Column>; |
14 | | - } |
| 14 | + @Predicate({ name: 'from_column', type: () => Column }) |
| 15 | + fromColumn: IPredicate<Column>; |
| 16 | + } |
15 | 17 |
|
16 | | - @Node() |
17 | | - class Row { |
18 | | - @Uid() |
19 | | - uid: string; |
| 18 | + @Node() |
| 19 | + class Row { |
| 20 | + @Uid() |
| 21 | + uid: string; |
20 | 22 |
|
21 | | - @Predicate({ name: 'has_cell', type: () => Cell }) |
22 | | - hasCell: IPredicate<Cell>; |
23 | | - } |
| 23 | + @Predicate({ name: 'has_cell', type: () => Cell }) |
| 24 | + hasCell: IPredicate<Cell>; |
| 25 | + } |
24 | 26 |
|
25 | | - @Node() |
26 | | - class Column { |
27 | | - @Uid() |
28 | | - uid: string; |
| 27 | + @Node() |
| 28 | + class Column { |
| 29 | + @Uid() |
| 30 | + uid: string; |
29 | 31 |
|
30 | | - @Predicate({ name: 'has_cell', type: () => Cell }) |
31 | | - hasCell: IPredicate<Cell>; |
32 | | - } |
| 32 | + @Predicate({ name: 'has_cell', type: () => Cell }) |
| 33 | + hasCell: IPredicate<Cell>; |
| 34 | + } |
33 | 35 |
|
34 | | - const transaction = TransactionBuilder.build(); |
| 36 | + const transaction = TransactionBuilder.build(); |
35 | 37 |
|
36 | | - const column = transaction.nodeFor(Column); |
| 38 | + const column = transaction.nodeFor(Column); |
37 | 39 |
|
38 | | - const times = 1000; |
| 40 | + const times = 1000; |
39 | 41 |
|
40 | | - let i = 0; |
41 | | - while (i++ < times) { |
42 | | - const cell = transaction.nodeFor(Cell); |
43 | | - const row = transaction.nodeFor(Row); |
| 42 | + let i = 0; |
| 43 | + while (i++ < times) { |
| 44 | + const cell = transaction.nodeFor(Cell); |
| 45 | + const row = transaction.nodeFor(Row); |
44 | 46 |
|
45 | | - cell.fromRow.add(row); |
46 | | - cell.fromColumn.add(column); |
| 47 | + cell.fromRow.add(row); |
| 48 | + cell.fromColumn.add(column); |
47 | 49 |
|
48 | | - row.hasCell.add(cell); |
49 | | - column.hasCell.add(cell); |
50 | | - } |
| 50 | + row.hasCell.add(cell); |
| 51 | + column.hasCell.add(cell); |
| 52 | + } |
51 | 53 |
|
52 | | - console.time('Initial'); |
53 | | - transaction.getSetNQuadsString(); |
54 | | - console.timeEnd('Initial'); |
| 54 | + console.time('Initial'); |
| 55 | + transaction.getSetNQuadsString(); |
| 56 | + console.timeEnd('Initial'); |
55 | 57 |
|
56 | | - const transaction2 = TransactionBuilder.build(); |
57 | | - const column2 = transaction2.nodeFor(Column); |
| 58 | + const transaction2 = TransactionBuilder.build(); |
| 59 | + const column2 = transaction2.nodeFor(Column); |
58 | 60 |
|
59 | | - i = 0; |
60 | | - while (i++ < times) { |
61 | | - const cell2 = transaction2.nodeFor(Cell); |
62 | | - const row2 = transaction2.nodeFor(Row); |
| 61 | + i = 0; |
| 62 | + while (i++ < times) { |
| 63 | + const cell2 = transaction2.nodeFor(Cell); |
| 64 | + const row2 = transaction2.nodeFor(Row); |
63 | 65 |
|
64 | | - cell2.fromRow.add(row2); |
65 | | - cell2.fromColumn.add(column2); |
| 66 | + cell2.fromRow.add(row2); |
| 67 | + cell2.fromColumn.add(column2); |
66 | 68 |
|
67 | | - row2.hasCell.add(cell2); |
68 | | - column2.hasCell.add(cell2); |
69 | | - } |
| 69 | + row2.hasCell.add(cell2); |
| 70 | + column2.hasCell.add(cell2); |
| 71 | + } |
70 | 72 |
|
71 | | - console.time('Second'); |
72 | | - transaction2.getSetNQuadsString(); |
73 | | - console.timeEnd('Second'); |
| 73 | + console.time('Second'); |
| 74 | + transaction2.getSetNQuadsString(); |
| 75 | + console.timeEnd('Second'); |
| 76 | + }); |
| 77 | + |
| 78 | + it.only('Fuzz with random data', () => { |
| 79 | + @Node() |
| 80 | + class Station { |
| 81 | + @Uid() |
| 82 | + uid: string; |
| 83 | + |
| 84 | + @Property() |
| 85 | + name: string; |
| 86 | + |
| 87 | + @Predicate({ type: () => Station }) |
| 88 | + connects: IPredicate<Station>; |
| 89 | + } |
| 90 | + |
| 91 | + const STATION_COUNT = 5; |
| 92 | + |
| 93 | + const allStations = new Array(STATION_COUNT).fill(null).map((_, idx) => ({ |
| 94 | + uid: `${idx}`, |
| 95 | + name: `Station_${idx}`, |
| 96 | + stations: [] as any[] |
| 97 | + })); |
| 98 | + |
| 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])); |
| 102 | + }); |
| 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 })); |
| 111 | + }); |
74 | 112 | }); |
0 commit comments