-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
36,988 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { cloneDeep } from 'lodash' | ||
|
||
/** Unsafe JSON clone */ | ||
// export const clone = (obj) => JSON.parse(JSON.stringify(obj)) | ||
export const clone = cloneDeep |
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 Bench from 'benchmark' | ||
import { writeFile, ensureDir } from 'fs-extra' | ||
import { dirname } from 'path' | ||
import { cloneDeep } from 'lodash' | ||
|
||
export class Benchmark { | ||
key; | ||
config; | ||
|
||
constructor (key, config = {}) { | ||
Object.assign(this, { key, config }) | ||
} | ||
|
||
async run (task) { | ||
async function fn (defer) { | ||
await task() | ||
defer.resolve() | ||
} | ||
|
||
this.results = [] | ||
|
||
await new Promise((resolve) => { | ||
const bench = new Bench(this.key, { | ||
defer: true, | ||
async: true, | ||
onComplete: resolve, | ||
onCycle: (event) => { | ||
this.results.push(cloneDeep(event.target)) | ||
|
||
if (this.config.onCycle) { this.config.onCycle(event) } | ||
}, | ||
fn, | ||
...this.config | ||
}) | ||
|
||
bench.run() | ||
}) | ||
|
||
return this | ||
} | ||
|
||
serialize (results = this.results) { | ||
return results.slice(-3).map((result) => { | ||
return String(result) | ||
}).join('\n') | ||
} | ||
|
||
async saveSnapshot (filePath, results = this.results) { | ||
const dir = dirname(filePath) | ||
|
||
await ensureDir(dir) | ||
return writeFile(filePath, this.serialize(results), 'utf8') | ||
} | ||
} |
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,2 @@ | ||
export { default as petStore } from './petStore' | ||
export { default as temandoFull } from './temandoFull' |
Oops, something went wrong.