|
1 | | -const Benchmark = require('benchmark'); |
| 1 | +const Benchmark = require("benchmark"); |
2 | 2 |
|
3 | | -const testFixture = require('../test/globals'); |
4 | | -const _ = testFixture.requirejs('underscore'); |
5 | | -const Core = testFixture.requirejs('common/core/coreQ'); |
6 | | -const Importer = testFixture.requirejs('webgme-json-importer/JSONImporter'); |
| 3 | +const testFixture = require("../test/globals"); |
| 4 | +const _ = testFixture.requirejs("underscore"); |
| 5 | +const Core = testFixture.requirejs("common/core/coreQ"); |
| 6 | +const Importer = testFixture.requirejs("webgme-json-importer/JSONImporter"); |
7 | 7 | const gmeConfig = testFixture.getGmeConfig(); |
8 | 8 | const Q = testFixture.Q; |
9 | | -const logger = testFixture.logger.fork('JSONImporter'); |
10 | | -const projectName = 'testProject'; |
| 9 | +const logger = testFixture.logger.fork("JSONImporter"); |
| 10 | +const projectName = "testProject"; |
11 | 11 |
|
12 | 12 | // let |
13 | 13 |
|
14 | 14 | class WJIBenchmark { |
15 | | - constructor(projectSeedName, callable) { |
16 | | - this.projectSeedName = projectSeedName; |
17 | | - this.project = null; |
18 | | - this.gmeAuth = null; |
19 | | - this.storage = null; |
20 | | - this.commitHash = null; |
21 | | - this.core = null; |
22 | | - this.branchCounter = 1; |
23 | | - this.callable = callable; |
24 | | - this.suite = new Benchmark.Suite(); |
25 | | - } |
| 15 | + constructor(projectSeedName, callable) { |
| 16 | + this.projectSeedName = projectSeedName; |
| 17 | + this.project = null; |
| 18 | + this.gmeAuth = null; |
| 19 | + this.storage = null; |
| 20 | + this.commitHash = null; |
| 21 | + this.core = null; |
| 22 | + this.branchCounter = 1; |
| 23 | + this.callable = callable; |
| 24 | + this.suite = new Benchmark.Suite(); |
| 25 | + } |
26 | 26 |
|
27 | | - async getNewRootNode() { |
28 | | - const branchName = 'test' + this.branchCounter++; |
29 | | - await this.project.createBranch(branchName, this.commitHash); |
30 | | - const branchHash = await this.project.getBranchHash(branchName); |
31 | | - const commit = await Q.ninvoke(this.project, 'loadObject', branchHash); |
32 | | - return await Q.ninvoke(this.core, 'loadRoot', commit.root); |
33 | | - } |
| 27 | + async getNewRootNode() { |
| 28 | + const branchName = "test" + this.branchCounter++; |
| 29 | + await this.project.createBranch(branchName, this.commitHash); |
| 30 | + const branchHash = await this.project.getBranchHash(branchName); |
| 31 | + const commit = await Q.ninvoke(this.project, "loadObject", branchHash); |
| 32 | + return await Q.ninvoke(this.core, "loadRoot", commit.root); |
| 33 | + } |
34 | 34 |
|
35 | | - async getNewProject() { |
36 | | - const root = await this.getNewRootNode(this.core); |
37 | | - const fco = await this.core.loadByPath(root, '/1'); |
38 | | - const importer = new Importer(this.core, root); |
39 | | - return { |
40 | | - root, |
41 | | - fco, |
42 | | - importer, |
43 | | - }; |
44 | | - } |
| 35 | + async getNewProject() { |
| 36 | + const root = await this.getNewRootNode(this.core); |
| 37 | + const fco = await this.core.loadByPath(root, "/1"); |
| 38 | + const importer = new Importer(this.core, root); |
| 39 | + return { |
| 40 | + root, |
| 41 | + fco, |
| 42 | + importer, |
| 43 | + }; |
| 44 | + } |
45 | 45 |
|
46 | | - async before() { |
47 | | - await this._setupGME(); |
48 | | - } |
| 46 | + async before() { |
| 47 | + await this._setupGME(); |
| 48 | + } |
49 | 49 |
|
50 | | - async _setupGME() { |
51 | | - this.gmeAuth = await testFixture.clearDBAndGetGMEAuth( |
52 | | - gmeConfig, |
53 | | - projectName |
54 | | - ); |
55 | | - this.storage = testFixture.getMemoryStorage( |
56 | | - logger, |
57 | | - gmeConfig, |
58 | | - this.gmeAuth |
59 | | - ); |
60 | | - await this.storage.openDatabase(); |
61 | | - const importParam = { |
62 | | - projectSeed: testFixture.path.join( |
63 | | - testFixture.TESTS_SEED_DIR, |
64 | | - this.projectSeedName, |
65 | | - `${this.projectSeedName}.webgmex` |
66 | | - ), |
67 | | - projectName: projectName, |
68 | | - branchName: 'master', |
69 | | - logger: logger, |
70 | | - gmeConfig: gmeConfig, |
71 | | - }; |
| 50 | + async _setupGME() { |
| 51 | + this.gmeAuth = await testFixture.clearDBAndGetGMEAuth( |
| 52 | + gmeConfig, |
| 53 | + projectName, |
| 54 | + ); |
| 55 | + this.storage = testFixture.getMemoryStorage( |
| 56 | + logger, |
| 57 | + gmeConfig, |
| 58 | + this.gmeAuth, |
| 59 | + ); |
| 60 | + await this.storage.openDatabase(); |
| 61 | + const importParam = { |
| 62 | + projectSeed: testFixture.path.join( |
| 63 | + testFixture.TESTS_SEED_DIR, |
| 64 | + this.projectSeedName, |
| 65 | + `${this.projectSeedName}.webgmex`, |
| 66 | + ), |
| 67 | + projectName: projectName, |
| 68 | + branchName: "master", |
| 69 | + logger: logger, |
| 70 | + gmeConfig: gmeConfig, |
| 71 | + }; |
72 | 72 |
|
73 | | - const importResult = await testFixture.importProject( |
74 | | - this.storage, |
75 | | - importParam |
76 | | - ); |
77 | | - this.project = importResult.project; |
78 | | - this.core = new Core(this.project, { |
79 | | - globConf: gmeConfig, |
80 | | - logger: logger.fork('core'), |
81 | | - }); |
82 | | - this.commitHash = importResult.commitHash; |
83 | | - } |
| 73 | + const importResult = await testFixture.importProject( |
| 74 | + this.storage, |
| 75 | + importParam, |
| 76 | + ); |
| 77 | + this.project = importResult.project; |
| 78 | + this.core = new Core(this.project, { |
| 79 | + globConf: gmeConfig, |
| 80 | + logger: logger.fork("core"), |
| 81 | + }); |
| 82 | + this.commitHash = importResult.commitHash; |
| 83 | + } |
84 | 84 |
|
85 | | - async after() { |
86 | | - await this.storage.closeDatabase(); |
87 | | - await this.gmeAuth.unload(); |
88 | | - } |
| 85 | + async after() { |
| 86 | + await this.storage.closeDatabase(); |
| 87 | + await this.gmeAuth.unload(); |
| 88 | + } |
89 | 89 |
|
90 | | - async run() { |
91 | | - await this.before(); |
92 | | - const { root, fco, importer } = await this.getNewProject(); |
93 | | - await this.callable({ |
94 | | - root, |
95 | | - fco, |
96 | | - importer, |
97 | | - core: this.core, |
98 | | - suite: this.suite, |
99 | | - }); |
100 | | - this.suite |
101 | | - .on('complete', function () { |
102 | | - this.forEach((bench) => console.log(bench.stats)); |
103 | | - }) |
104 | | - .run({ async: true }); // runAsync |
105 | | - await this.after(); |
106 | | - } |
| 90 | + async run() { |
| 91 | + await this.before(); |
| 92 | + const { root, fco, importer } = await this.getNewProject(); |
| 93 | + await this.callable({ |
| 94 | + root, |
| 95 | + fco, |
| 96 | + importer, |
| 97 | + core: this.core, |
| 98 | + suite: this.suite, |
| 99 | + }); |
| 100 | + this.suite |
| 101 | + .on("complete", function () { |
| 102 | + this.forEach((bench) => console.log(bench.stats)); |
| 103 | + }) |
| 104 | + .run({ async: true }); // runAsync |
| 105 | + await this.after(); |
| 106 | + } |
107 | 107 | } |
108 | 108 |
|
109 | 109 | module.exports = WJIBenchmark; |
0 commit comments