-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding Optimizations for Screenshot and all
- Loading branch information
Showing
8 changed files
with
222 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
packages/webdriver-utils/src/providers/automateProvider.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import validations from './validations.js'; | ||
const { Undefined } = validations; | ||
|
||
export default class TimeIt { | ||
static data = {}; | ||
|
||
static enabled = process.env.PERCY_METRICS === 'true'; | ||
|
||
static async run(store, func) { | ||
if (!this.enabled) return await func(); | ||
|
||
const t1 = Date.now(); | ||
try { | ||
return await func(); | ||
} finally { | ||
if (Undefined(this.data[store])) this.data[store] = []; | ||
this.data[store].push(Date.now() - t1); | ||
} | ||
} | ||
|
||
static min(store) { | ||
return Math.min(...this.data[store]); | ||
} | ||
|
||
static max(store) { | ||
return Math.max(...this.data[store]); | ||
} | ||
|
||
static avg(store) { | ||
const vals = this.data[store]; | ||
|
||
return vals.reduce((a, b) => a + b, 0) / vals.length; | ||
} | ||
|
||
static summary({ | ||
includeVals | ||
} = {}) { | ||
const agg = {}; | ||
for (const key of Object.keys(this.data)) { | ||
agg[key] = { | ||
min: this.min(key), | ||
max: this.max(key), | ||
avg: this.avg(key), | ||
count: this.data[key].length | ||
}; | ||
if (includeVals) agg[key].vals = this.data[key]; | ||
} | ||
return agg; | ||
} | ||
|
||
static reset() { | ||
this.data = {}; | ||
} | ||
}; |