Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add Paseri to benchmarks #1503

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ cases/typia/build
cases/deepkit/build
cases/ts-auto-guard/build
cases/ts-auto-guard/src/index.guard.ts
jest.config.js
cases/jointz/build
jest.config.js
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -164,4 +164,7 @@ cases/typia/build

# ts-auto-guard build artifacts
cases/ts-auto-guard/build
cases/ts-auto-guard/src/index.guard.ts
cases/ts-auto-guard/src/index.guard.ts

# jointz build artifacts
cases/jointz/build
3 changes: 2 additions & 1 deletion .npmrc
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
save-exact=true
save-exact=true
@jsr:registry=https://npm.jsr.io
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why we need this?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This just adds a link to the jsr.io package registry, which is a modern version of the npm registry. Paseri is hosted there only, not on npm. https://jsr.io/#why-jsr

File renamed without changes.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
* [pure-parse](https://github.com/johannes-lindgren/pure-parse)
* [purify-ts](https://github.com/gigobyte/purify)
* [parse-dont-validate](https://github.com/Packer-Man/parse-dont-validate)
* [Paseri](https://github.com/vbudovski/paseri)
* [r-assign](https://github.com/micnic/r-assign)
* [rescript-schema](https://github.com/DZakh/rescript-schema)
* [rulr](https://github.com/ryansmith94/rulr)
Expand Down
4 changes: 2 additions & 2 deletions benchmarks/assertLoose.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Benchmark } from './helpers/types';
import { validateData } from './parseSafe';
import { Benchmark } from './helpers/types.ts';
import { validateData } from './parseSafe.ts';

type Fn = (data: unknown) => boolean;

Expand Down
4 changes: 2 additions & 2 deletions benchmarks/assertStrict.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Benchmark } from './helpers/types';
import { validateData } from './parseSafe';
import { Benchmark } from './helpers/types.ts';
import { validateData } from './parseSafe.ts';

type Fn = (data: unknown) => boolean;

Expand Down
7 changes: 5 additions & 2 deletions benchmarks/helpers/graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ import { writeFileSync } from 'fs';
import { optimize } from 'svgo';
import { parse, View } from 'vega';
import { compile } from 'vega-lite';
import { availableBenchmarks, type AvailableBenchmarksIds } from './register';
import type { BenchmarkResult } from './types';
import {
availableBenchmarks,
type AvailableBenchmarksIds,
} from './register.ts';
import type { BenchmarkResult } from './types.ts';

interface PreviewGraphParams {
values: BenchmarkResult[];
Expand Down
9 changes: 5 additions & 4 deletions benchmarks/helpers/main.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { add, complete, cycle, suite } from 'benny';
import { readFileSync, writeFileSync, existsSync, unlinkSync } from 'fs';
import { join } from 'path';
import { writePreviewGraph } from './graph';
import { getRegisteredBenchmarks } from './register';
import type { BenchmarkCase, BenchmarkResult } from './types';
import { fileURLToPath } from 'url';
import { writePreviewGraph } from './graph.ts';
import { getRegisteredBenchmarks } from './register.ts';
import type { BenchmarkCase, BenchmarkResult } from './types.ts';

const DOCS_DIR = join(__dirname, '../../docs');
const DOCS_DIR = join(fileURLToPath(import.meta.url), '../../../docs');
const RUNTIME = process.env.RUNTIME || 'node';
const RUNTIME_VERSION = process.env.RUNTIME_VERSION || process.version;
const RUNTIME_FOR_PREVIEW = 'node';
Expand Down
10 changes: 5 additions & 5 deletions benchmarks/helpers/register.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { AssertLoose } from '../assertLoose';
import { AssertStrict } from '../assertStrict';
import { ParseSafe } from '../parseSafe';
import { ParseStrict } from '../parseStrict';
import type { BenchmarkCase } from './types';
import { AssertLoose } from '../assertLoose.ts';
import { AssertStrict } from '../assertStrict.ts';
import { ParseSafe } from '../parseSafe.ts';
import { ParseStrict } from '../parseStrict.ts';
import type { BenchmarkCase } from './types.ts';

/**
* Map of all benchmarks.
Expand Down
6 changes: 3 additions & 3 deletions benchmarks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ export {
runAllBenchmarks,
createPreviewGraph,
deleteResults,
} from './helpers/main';
} from './helpers/main.ts';
export {
addCase,
type AvailableBenchmarksIds,
createCase,
getRegisteredBenchmarks,
} from './helpers/register';
export { type UnknownData } from './helpers/types';
} from './helpers/register.ts';
export { type UnknownData } from './helpers/types.ts';
2 changes: 1 addition & 1 deletion benchmarks/parseSafe.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Benchmark } from './helpers/types';
import { Benchmark } from './helpers/types.ts';

export const validateData = Object.freeze({
number: 1,
Expand Down
4 changes: 2 additions & 2 deletions benchmarks/parseStrict.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Benchmark } from './helpers/types';
import { validateData } from './parseSafe';
import { Benchmark } from './helpers/types.ts';
import { validateData } from './parseSafe.ts';

type Fn = (data: unknown) => typeof validateData;

Expand Down
Binary file modified bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion cases/aeria/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { validate } from '@aeriajs/validation';
import { createCase } from '../../benchmarks';
import { createCase } from '../../benchmarks/index.ts';

const schema = {
type: 'object',
Expand Down
2 changes: 1 addition & 1 deletion cases/ajv.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Ajv from 'ajv';
import { createCase } from '../benchmarks';
import { createCase } from '../benchmarks/index.ts';

createCase('ajv', 'assertLoose', () => {
const ajv = new Ajv();
Expand Down
2 changes: 1 addition & 1 deletion cases/arktype.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type } from 'arktype';
import { createCase } from '../benchmarks';
import { createCase } from '../benchmarks/index.ts';

const t = type({
number: 'number',
Expand Down
2 changes: 1 addition & 1 deletion cases/banditypes.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { boolean, number, object, string } from 'banditypes';
import { addCase } from '../benchmarks';
import { addCase } from '../benchmarks/index.ts';

const dataTypeSafe = object({
number: number(),
Expand Down
2 changes: 1 addition & 1 deletion cases/bueno.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
result,
string,
} from 'bueno';
import { type UnknownData, addCase } from '../benchmarks';
import { type UnknownData, addCase } from '../benchmarks/index.ts';

const dataType = object({
number: number,
Expand Down
2 changes: 1 addition & 1 deletion cases/caketype.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { bake, boolean, number, string } from 'caketype';
import { createCase } from '../benchmarks';
import { createCase } from '../benchmarks/index.ts';

const cake = bake({
number: number,
Expand Down
2 changes: 1 addition & 1 deletion cases/class-validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
ValidateNested,
} from 'class-validator';
import 'reflect-metadata';
import { createCase } from '../benchmarks';
import { createCase } from '../benchmarks/index.ts';

createCase('class-transformer-validator-sync', 'assertLoose', () => {
class DeeplyNestedType {
Expand Down
4 changes: 3 additions & 1 deletion cases/computed-types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import Schema, { boolean, number, string } from 'computed-types';
import { type UnknownData, addCase } from '../benchmarks';
import { type UnknownData, addCase } from '../benchmarks/index.ts';

const validator = Schema({
number: number,
Expand Down
2 changes: 1 addition & 1 deletion cases/decoders.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { boolean, exact, guard, number, object, string } from 'decoders';
import { createCase } from '../benchmarks';
import { createCase } from '../benchmarks/index.ts';

createCase('decoders', 'parseSafe', () => {
const dataType = object({
Expand Down
20 changes: 7 additions & 13 deletions cases/deepkit/build/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cases/deepkit/build/index.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions cases/deepkit/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { parseSafe, assertLoose } from './build';
import { addCase } from '../../benchmarks';
import { parseSafe, assertLoose } from './build/index.js';
import { addCase } from '../../benchmarks/index.ts';

addCase('deepkit', 'parseSafe', data => {
return parseSafe(data);
Expand Down
5 changes: 3 additions & 2 deletions cases/deepkit/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"module": "commonjs",
"outDir": "build"
"module": "ESNext",
"outDir": "build",
"allowImportingTsExtensions": false
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please explain what these changes do

Copy link
Author

@vbudovski vbudovski Dec 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we inherited the tsconfig we need to flip the allowImportingTsExtensions setting, because it won’t work when transpiling, only for generating types. https://www.typescriptlang.org/tsconfig/#allowImportingTsExtensions

The other two changes here are to make this module ESM to match the top-level module, since we can’t mix commonjs/ESM.

},
"include": ["src/index.ts"],
"reflection": true
Expand Down
2 changes: 1 addition & 1 deletion cases/effect-schema.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Schema } from '@effect/schema';
import { createCase } from '../benchmarks';
import { createCase } from '../benchmarks/index.ts';

createCase('effect-schema', 'parseSafe', () => {
const dataType = Schema.Struct({
Expand Down
11 changes: 10 additions & 1 deletion cases/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const cases = [
'parse-dont-validate',
'pure-parse',
'purify-ts',
'paseri',
'r-assign',
'rescript-schema',
'rulr',
Expand Down Expand Up @@ -57,5 +58,13 @@ export const cases = [
export type CaseName = (typeof cases)[number];

export async function importCase(caseName: CaseName) {
await import('./' + caseName);
try {
await import(`./${caseName}.ts`);
} catch {
try {
await import(`./${caseName}/index.ts`);
} catch (e) {
console.error(`Could not import ${caseName}.`, e);
}
}
}
6 changes: 3 additions & 3 deletions cases/io-ts.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { fold } from 'fp-ts/Either';
import { pipe } from 'fp-ts/function';
import { fold } from 'fp-ts/lib/Either.js';
import { pipe } from 'fp-ts/lib/function.js';
import * as t from 'io-ts';
import { createCase } from '../benchmarks';
import { createCase } from '../benchmarks/index.ts';

createCase('io-ts', 'assertLoose', () => {
const dataType = t.type({
Expand Down
6 changes: 4 additions & 2 deletions cases/jet-schema.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import jetSchema from 'jet-schema';
import { createCase } from '../benchmarks';
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import jetSchema from 'jet-schema/dist/index.min.mjs';
import { createCase } from '../benchmarks/index.ts';

// **** Init Schema **** //

Expand Down
4 changes: 2 additions & 2 deletions cases/jointz.ts → cases/jointz/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import jointz from 'jointz';
import { addCase } from '../benchmarks';
import jointz from './build/index.js';
import { addCase } from '../../benchmarks/index.js';

const dataTypeLoose = jointz
.object({
Expand Down
3 changes: 3 additions & 0 deletions cases/jointz/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { default as jointz } from 'jointz/src/index';

export default jointz;
12 changes: 12 additions & 0 deletions cases/jointz/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"module": "CommonJS",
"moduleResolution": "Node",
"outDir": "build",
"strict": true,
"declaration": true,
"emitDeclarationOnly": true
},
"include": ["src/index.ts"]
}
2 changes: 1 addition & 1 deletion cases/json-decoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
numberDecoder,
boolDecoder,
} from 'json-decoder';
import { createCase } from '../benchmarks';
import { createCase } from '../benchmarks/index.ts';

createCase('json-decoder', 'parseSafe', () => {
const dataType = objectDecoder({
Expand Down
2 changes: 1 addition & 1 deletion cases/mojotech-json-type-validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
object,
boolean,
} from '@mojotech/json-type-validation';
import { createCase } from '../benchmarks';
import { createCase } from '../benchmarks/index.ts';

createCase('@mojotech/json-type-validation', 'parseSafe', () => {
const dataType = object({
Expand Down
2 changes: 1 addition & 1 deletion cases/mol_data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const {
$mol_data_boolean: Bool,
} = $;

import { createCase } from '../benchmarks';
import { createCase } from '../benchmarks/index.ts';

createCase('$mol_data', 'parseSafe', () => {
const dataType = Rec({
Expand Down
2 changes: 1 addition & 1 deletion cases/mondrian-framework.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createCase } from '../benchmarks';
import { createCase } from '../benchmarks/index.ts';
import { model } from '@mondrian-framework/model';

const dataType = model.object({
Expand Down
2 changes: 1 addition & 1 deletion cases/myzod.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import myzod from 'myzod';
import { addCase, createCase } from '../benchmarks';
import { addCase, createCase } from '../benchmarks/index.ts';

createCase('myzod', 'parseSafe', () => {
const dataType = myzod.object(
Expand Down
2 changes: 1 addition & 1 deletion cases/ok-computer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { boolean, number, object, string, assert } from 'ok-computer';
import { type UnknownData, addCase } from '../benchmarks';
import { type UnknownData, addCase } from '../benchmarks/index.ts';

const dataType = object({
number: number,
Expand Down
2 changes: 1 addition & 1 deletion cases/parse-dont-validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import parse, {
parseAsNumber,
parseAsString,
} from 'parse-dont-validate';
import { addCase } from '../benchmarks';
import { addCase } from '../benchmarks/index.ts';

addCase('parse-dont-validate (chained function)', 'parseSafe', data =>
parse(data)
Expand Down
Loading