-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.ts
44 lines (35 loc) · 1.52 KB
/
main.ts
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
43
44
import { ArrayUtils } from "./utils/ArrayUtils";
import { Comparable, SortAlgorithm } from "./algorithms/SortAlgorithm";
import { BubbleSort } from "./algorithms/BubbleSort";
import { QuickSort } from "./algorithms/QuickSort";
import { PigeonholeSort } from "./algorithms/PigeonholeSort";
import { ObjectUtils } from "./utils/ObjectUtils";
import { CSVGenerator } from "./sheet/CSVGenerator";
import { FileUtils } from "./utils/FileUtils";
class NumberComparable extends Comparable<number> {
public clone() {
return new NumberComparable(this.getValue());
}
protected isGreaterThanOther(otherValue: number): boolean {
return this.getValue() > otherValue;
}
}
async function main() {
const values = ArrayUtils.generateRandomArray(50000, 100000).map(number => new NumberComparable(number));
const sorts: { [name: string]: SortAlgorithm<number> } = {
BubbleSort: new BubbleSort(values),
QuickSort: new QuickSort(values),
PigeonholeSort: new PigeonholeSort(values)
};
const algorithmNames = ObjectUtils.getKeys(sorts);
const results = algorithmNames.map(
(algorithmName) => {
console.info(`Running ${algorithmName}.`);
const results = sorts[algorithmName].sort();
console.info(`Done running ${algorithmName} (${results.executionTime / 1000}s).`)
return { algorithmName, ...results };
}
);
await FileUtils.writeFileAsync('artifacts/result.csv', CSVGenerator.generateCSV(results));
}
main();