Skip to content

Commit e09b59b

Browse files
CopilotDevilTea
andcommitted
perf(benchmarks): remove Pipe class completely, merge benchmark files, fix type check issues
Co-authored-by: DevilTea <16652879+DevilTea@users.noreply.github.com>
1 parent 29eec38 commit e09b59b

File tree

9 files changed

+190
-277
lines changed

9 files changed

+190
-277
lines changed

benchmarks/all-steps.bench.ts

Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,3 +373,183 @@ describe('generic Operations', () => {
373373
schema.execute('hello')
374374
})
375375
})
376+
377+
// Additional detailed benchmarks for comprehensive performance testing
378+
379+
describe('detailed - String Operations', () => {
380+
bench('string - with startsWith constraint', () => {
381+
const v = createValchecker({ steps: [string, startsWith] })
382+
const schema = v.string().startsWith('hello')
383+
schema.execute('hello world')
384+
})
385+
386+
bench('string - with endsWith constraint', () => {
387+
const v = createValchecker({ steps: [string, endsWith] })
388+
const schema = v.string().endsWith('world')
389+
schema.execute('hello world')
390+
})
391+
392+
bench('string - multiple transformations', () => {
393+
const v = createValchecker({ steps: [string, toLowercase, startsWith] })
394+
const schema = v.string()
395+
.toLowercase()
396+
.startsWith('hello')
397+
schema.execute('HELLO WORLD')
398+
})
399+
})
400+
401+
describe('detailed - Number Operations', () => {
402+
bench('number - with min constraint', () => {
403+
const v = createValchecker({ steps: [number, min] })
404+
const schema = v.number().min(0)
405+
schema.execute(42)
406+
})
407+
408+
bench('number - with max constraint', () => {
409+
const v = createValchecker({ steps: [number, max] })
410+
const schema = v.number().max(100)
411+
schema.execute(42)
412+
})
413+
414+
bench('number - with min and max', () => {
415+
const v = createValchecker({ steps: [number, min, max] })
416+
const schema = v.number()
417+
.min(0)
418+
.max(100)
419+
schema.execute(42)
420+
})
421+
})
422+
423+
describe('detailed - Check Function', () => {
424+
bench('check - simple boolean', () => {
425+
const v = createValchecker({ steps: [string, check] })
426+
const schema = v.string().check(x => x.length > 3)
427+
schema.execute('hello')
428+
})
429+
430+
bench('check - type guard', () => {
431+
const v = createValchecker({ steps: [string, check] })
432+
const schema = v.string().check((x): x is 'hello' => x === 'hello')
433+
schema.execute('hello')
434+
})
435+
436+
bench('check - complex validation', () => {
437+
const v = createValchecker({ steps: [string, check] })
438+
const schema = v.string().check(x => x.length > 3 && x.includes('o'))
439+
schema.execute('hello')
440+
})
441+
442+
bench('check - multiple checks', () => {
443+
const v = createValchecker({ steps: [string, check] })
444+
const schema = v.string()
445+
.check(x => x.length > 3)
446+
.check(x => x.includes('o'))
447+
.check(x => x.startsWith('h'))
448+
schema.execute('hello')
449+
})
450+
})
451+
452+
describe('detailed - Transform', () => {
453+
bench('transform - string to number', () => {
454+
const v = createValchecker({ steps: [string, transform] })
455+
const schema = v.string().transform(x => Number.parseInt(x, 10))
456+
schema.execute('42')
457+
})
458+
459+
bench('transform - multiple transforms', () => {
460+
const v = createValchecker({ steps: [string, transform] })
461+
const schema = v.string()
462+
.transform(x => x.toUpperCase())
463+
.transform(x => x.split(''))
464+
.transform(x => x.length)
465+
schema.execute('hello')
466+
})
467+
468+
bench('transform - with validation', () => {
469+
const v = createValchecker({ steps: [string, check, transform] })
470+
const schema = v.string()
471+
.check(x => x.length > 0)
472+
.transform(x => Number.parseInt(x, 10))
473+
.check(x => x > 0)
474+
schema.execute('42')
475+
})
476+
})
477+
478+
describe('detailed - Fallback', () => {
479+
bench('fallback - success path', () => {
480+
const v = createValchecker({ steps: [string, fallback] })
481+
const schema = v.string().fallback('default')
482+
schema.execute('hello')
483+
})
484+
485+
bench('fallback - failure path', () => {
486+
const v = createValchecker({ steps: [string, fallback] })
487+
const schema = v.string().fallback('default')
488+
schema.execute(42)
489+
})
490+
})
491+
492+
describe('detailed - Array Operations', () => {
493+
bench('array - with element validation', () => {
494+
const v = createValchecker({ steps: [array, string, check] })
495+
const schema = v.array(v.string().check(x => x.length > 0))
496+
schema.execute(['a', 'b', 'c', 'd', 'e'])
497+
})
498+
499+
bench('array - with element transformation', () => {
500+
const v = createValchecker({ steps: [array, string, transform] })
501+
const schema = v.array(v.string().transform(x => x.toUpperCase()))
502+
schema.execute(['a', 'b', 'c', 'd', 'e'])
503+
})
504+
})
505+
506+
describe('detailed - Object Operations', () => {
507+
bench('object - with field validations', () => {
508+
const v = createValchecker({ steps: [object, string, number, check] })
509+
const schema = v.object({
510+
name: v.string().check(x => x.length > 0),
511+
age: v.number().check(x => x > 0),
512+
email: v.string().check(x => x.includes('@')),
513+
})
514+
schema.execute({ name: 'John', age: 30, email: 'john@example.com' })
515+
})
516+
517+
bench('object - with field transformations', () => {
518+
const v = createValchecker({ steps: [object, string, number, transform] })
519+
const schema = v.object({
520+
name: v.string().transform(x => x.toUpperCase()),
521+
age: v.number().transform(x => x * 2),
522+
email: v.string().transform(x => x.toLowerCase()),
523+
})
524+
schema.execute({ name: 'John', age: 30, email: 'JOHN@EXAMPLE.COM' })
525+
})
526+
})
527+
528+
describe('detailed - Chained Operations', () => {
529+
bench('string - 3 step chain', () => {
530+
const v = createValchecker({ steps: [string, toLowercase, startsWith] })
531+
const schema = v.string()
532+
.toLowercase()
533+
.startsWith('hello')
534+
schema.execute('HELLO WORLD')
535+
})
536+
537+
bench('string - 5 step chain', () => {
538+
const v = createValchecker({ steps: [string, toLowercase, startsWith, check, transform] })
539+
const schema = v.string()
540+
.toLowercase()
541+
.startsWith('hello')
542+
.check(x => x.length > 5)
543+
.transform(x => x.split(' '))
544+
schema.execute('HELLO WORLD')
545+
})
546+
547+
bench('number - 4 step chain', () => {
548+
const v = createValchecker({ steps: [number, min, max, check] })
549+
const schema = v.number()
550+
.min(0)
551+
.max(100)
552+
.check(x => x % 2 === 0)
553+
schema.execute(42)
554+
})
555+
})

0 commit comments

Comments
 (0)