You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
1.6 KiB
TypeScript

import * as SWC from "../src/swc.ts";
import { CallExpression, ExpressionStatement } from "../src/swc.ts";
import * as Trans from "../src/transformers.ts";
const input = Deno.readTextFileSync("./benchmarks/benchtest.ts");
const fakeState = {
input: "",
indent: " ",
idents: new Map<string, Trans.Ident>(),
opts: {
indent: 4,
showSourceStatements: false,
attr: {},
meta: {},
}
};
const ast = SWC.parse(input, {
syntax: "typescript",
comments: true,
target: "es2020",
});
const template = Deno.readTextFileSync("./assets/template.fprg");
Deno.bench("transform", () => {
Trans.transform(input, ast, {
indent: 3,
showSourceStatements: true,
}, template);
});
Deno.bench("transformBlock", () => {
Trans.transformBlock(
ast.body,
{ ...fakeState, idents: new Map<string, Trans.Ident>() },
);
});
Deno.bench("transformVariableDecl", () => {
Trans.transformVariableDecl(
ast.body[7] as SWC.VariableDeclaration,
{ ...fakeState, idents: new Map<string, Trans.Ident>() },
);
});
fakeState.idents = new Map<string, Trans.Ident>([
["a", { type: "int", defined: true }],
["b", { type: "int", defined: true }],
]);
Deno.bench("transformExpr :: `20 / ((5 + a) ^ (a + b))`", () => {
Trans.transformExpr(
(ast.body[10] as SWC.VariableDeclaration).declarations[0].init!,
fakeState.idents,
);
});
Deno.bench("transformBlockCallExpr :: `print(a + b)`", () => {
Trans.transformBlockCallExpr(
(ast.body[9] as ExpressionStatement).expression as CallExpression,
fakeState,
);
});
Deno.bench("transformIfStmt", () => {
Trans.transformIfStmt(
ast.body[19] as SWC.IfStatement,
fakeState
);
});