Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.

Commit df96c6b

Browse files
committed
refactor: update benchmarks code
1 parent ac6f140 commit df96c6b

7 files changed

Lines changed: 33 additions & 27 deletions

File tree

benchmarks/array.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
import Joi from 'joi'
1212
import { z } from 'zod'
13-
import { Suite } from 'benchmark'
13+
import benchmark from 'benchmark'
1414
import { validateOrReject, ValidateNested, IsString } from 'class-validator'
1515

1616
import { validate } from './validate.js'
@@ -88,7 +88,7 @@ type Deferred = { resolve(): any }
8888
/**
8989
* Starting benchmark
9090
*/
91-
new Suite()
91+
new benchmark.Suite()
9292
.add('AdonisJS', {
9393
defer: true,
9494
fn(deferred: Deferred) {
@@ -151,7 +151,7 @@ new Suite()
151151
.on('cycle', function cycle(event: any) {
152152
console.log(String(event.target))
153153
})
154-
.on('complete', function (this: Suite) {
154+
.on('complete', function (this: benchmark.Suite) {
155155
console.log('Fastest is ' + this.filter('fastest').map('name'))
156156
})
157157
.run({ async: true })

benchmarks/flat_object.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
import Joi from 'joi'
1212
import { z } from 'zod'
13-
import { Suite } from 'benchmark'
13+
import benchmark from 'benchmark'
1414
import { validateOrReject, IsString } from 'class-validator'
1515

1616
import { Compiler } from '../src/compiler/index.js'
@@ -63,7 +63,7 @@ type Deferred = { resolve(): any }
6363
/**
6464
* Starting benchmark
6565
*/
66-
new Suite()
66+
new benchmark.Suite()
6767
.add('AdonisJS', {
6868
defer: true,
6969
fn(deferred: Deferred) {
@@ -94,7 +94,7 @@ new Suite()
9494
.on('cycle', function cycle(event: any) {
9595
console.log(String(event.target))
9696
})
97-
.on('complete', function (this: Suite) {
97+
.on('complete', function (this: benchmark.Suite) {
9898
console.log('Fastest is ' + this.filter('fastest').map('name'))
9999
})
100100
.run({ async: true })

benchmarks/flat_object_extra_properties.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
import Joi from 'joi'
1414
import { z } from 'zod'
15-
import { Suite } from 'benchmark'
15+
import benchmark from 'benchmark'
1616

1717
import { Compiler } from '../src/compiler/index.js'
1818
import { schema } from '../src/schema/index.js'
@@ -49,7 +49,7 @@ type Deferred = { resolve(): any }
4949
/**
5050
* Starting benchmark
5151
*/
52-
new Suite()
52+
new benchmark.Suite()
5353
.add('AdonisJS', {
5454
defer: true,
5555
fn(deferred: Deferred) {
@@ -89,7 +89,7 @@ new Suite()
8989
.on('cycle', function cycle(event: any) {
9090
console.log(String(event.target))
9191
})
92-
.on('complete', function (this: Suite) {
92+
.on('complete', function (this: benchmark.Suite) {
9393
console.log('Fastest is ' + this.filter('fastest').map('name'))
9494
})
9595
.run({ async: true })

benchmarks/index.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,37 @@
1-
import { getDirname } from '@poppinss/utils'
1+
import kleur from 'kleur'
22
import { execaNode } from 'execa'
3-
import { cyan, green, red } from 'kleur'
3+
import { fileURLToPath } from 'node:url'
44

55
async function run() {
6-
console.log(cyan('Benchmarking against flat object'))
7-
await execaNode('./flat-object.js', {
8-
cwd: getDirname(new URL('./', import.meta.url)),
6+
console.log(kleur.cyan('Benchmarking against flat object'))
7+
await execaNode('./flat_object.js', {
8+
cwd: fileURLToPath(new URL('./', import.meta.url)),
99
stdio: 'inherit',
1010
})
1111

12-
console.log(cyan('Benchmarking against flat object with extra properties'))
13-
await execaNode('./flat-object-extra-properties.js', {
14-
cwd: getDirname(new URL('./', import.meta.url)),
12+
console.log(kleur.cyan('Benchmarking against flat object with extra properties'))
13+
await execaNode('./flat_object_extra_properties.js', {
14+
cwd: fileURLToPath(new URL('./', import.meta.url)),
1515
stdio: 'inherit',
1616
})
1717

18-
console.log(cyan('Benchmarking against nested object'))
19-
await execaNode('./nested-object.js', {
20-
cwd: getDirname(new URL('./', import.meta.url)),
18+
console.log(kleur.cyan('Benchmarking against nested object'))
19+
await execaNode('./nested_object.js', {
20+
cwd: fileURLToPath(new URL('./', import.meta.url)),
2121
stdio: 'inherit',
2222
})
2323

24-
console.log(cyan('Benchmarking against array of objects'))
24+
console.log(kleur.cyan('Benchmarking against array of objects'))
2525
await execaNode('./array.js', {
26-
cwd: getDirname(new URL('./', import.meta.url)),
26+
cwd: fileURLToPath(new URL('./', import.meta.url)),
2727
stdio: 'inherit',
2828
})
2929
}
3030

3131
run()
3232
.then(() => {
33-
console.log(green('completed'))
33+
console.log(kleur.green('completed'))
3434
})
3535
.catch((error) => {
36-
console.log(red(error))
36+
console.log(kleur.red(error))
3737
})

benchmarks/nested_object.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
import Joi from 'joi'
1212
import { z } from 'zod'
13-
import { Suite } from 'benchmark'
13+
import benchmark from 'benchmark'
1414
import { validateOrReject, ValidateNested, IsString } from 'class-validator'
1515

1616
import { validate } from './validate.js'
@@ -80,7 +80,7 @@ type Deferred = { resolve(): any }
8080
/**
8181
* Starting benchmark
8282
*/
83-
new Suite()
83+
new benchmark.Suite()
8484
.add('AdonisJS', {
8585
defer: true,
8686
fn(deferred: Deferred) {
@@ -137,7 +137,7 @@ new Suite()
137137
.on('cycle', function cycle(event: any) {
138138
console.log(String(event.target))
139139
})
140-
.on('complete', function (this: Suite) {
140+
.on('complete', function (this: benchmark.Suite) {
141141
console.log('Fastest is ' + this.filter('fastest').map('name'))
142142
})
143143
.run({ async: true })

index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,8 @@
66
* For the full copyright and license information, please view the LICENSE
77
* file that was distributed with this source code.
88
*/
9+
10+
export { rules } from './src/rules/index.js'
11+
export { schema } from './src/schema/index.js'
12+
export { validator } from './src/validator/index.js'
13+
export { ValidationException } from './src/validation_exception/index.js'

src/validator/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import {
3030
DefaultMessagesCallback,
3131
} from '../types.js'
3232

33+
import '../bindings/request.js'
3334
import { schema } from '../schema/index.js'
3435
import { Compiler } from '../compiler/index.js'
3536
import { rules, getRuleFn } from '../rules/index.js'

0 commit comments

Comments
 (0)