Skip to content

Commit

Permalink
Add write task
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Sep 19, 2021
1 parent 966eccf commit 8c5bf2a
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions benchmark/tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { promises as fs } from 'fs'
// eslint-disable-next-line no-shadow
import { setTimeout } from 'timers/promises'

import { tmpName } from 'tmp-promise'

const CURRENT_URL = new URL(import.meta.url)

// The fastest possible task
Expand Down Expand Up @@ -54,6 +56,24 @@ export const read = async function () {
await fs.readFile(CURRENT_URL)
}

// IO-bound write task
export const write = {
async beforeAll() {
// eslint-disable-next-line fp/no-mutation
fileContent = await fs.readFile(CURRENT_URL, 'utf8')
},
async beforeEach({ context }) {
// eslint-disable-next-line fp/no-mutation, no-param-reassign
context.tmpPath = await tmpName()
},
async main({ context: { tmpPath } }) {
await fs.writeFile(tmpPath, fileContent)
},
async afterEach({ context: { tmpPath } }) {
await fs.unlink(tmpPath)
},
}

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

0 comments on commit 8c5bf2a

Please sign in to comment.