Skip to content

Commit

Permalink
Add cpu task
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Sep 19, 2021
1 parent 7383428 commit be6ac15
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion benchmark/tasks.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// This is an example of tasks, used mostly for debugging
import { randomInt } from 'crypto'
import { randomInt, createHash } from 'crypto'
import { promises as fs } from 'fs'
// eslint-disable-next-line no-shadow
import { setTimeout } from 'timers/promises'

Expand Down Expand Up @@ -27,6 +28,25 @@ export const imprecise = function () {
randomInt(2)
}

// eslint-disable-next-line fp/no-let, init-declarations
let fileContent

// CPU-bound task
export const cpu = {
async beforeAll() {
// eslint-disable-next-line fp/no-mutation
fileContent = await fs.readFile(new URL(import.meta.url), 'utf8')
},
beforeEach({ context }) {
// eslint-disable-next-line no-param-reassign, fp/no-mutation
context.hash = createHash('sha256')
},
main({ context: { hash } }) {
hash.update(fileContent)
hash.digest('hex')
},
}

// Task with a high complexity mimicking real tasks
export const complex = async () => {
await import('spyd')
Expand Down

0 comments on commit be6ac15

Please sign in to comment.