From 58622848fd6687facc3496b6dec40b3f34e379af Mon Sep 17 00:00:00 2001 From: Mickey Rose Date: Fri, 15 Oct 2021 17:13:01 +0200 Subject: [PATCH] add benchmarks for `babel-types` builders --- .../babel-types/builders/memberExpression.mjs | 23 +++++++++++++++++++ .../babel-types/builders/stringLiteral.mjs | 21 +++++++++++++++++ benchmark/package.json | 2 ++ yarn.lock | 22 ++++++++++-------- 4 files changed, 58 insertions(+), 10 deletions(-) create mode 100644 benchmark/babel-types/builders/memberExpression.mjs create mode 100644 benchmark/babel-types/builders/stringLiteral.mjs diff --git a/benchmark/babel-types/builders/memberExpression.mjs b/benchmark/babel-types/builders/memberExpression.mjs new file mode 100644 index 000000000000..95b34a8bd46d --- /dev/null +++ b/benchmark/babel-types/builders/memberExpression.mjs @@ -0,0 +1,23 @@ +import Benchmark from "benchmark"; +import baseline from "@babel-baseline/types"; +import current from "@babel/types"; +import { report } from "../../util.mjs"; + +const suite = new Benchmark.Suite(); + +function benchCases(implementations) { + const funcName = "memberExpression"; + for (const version in implementations) { + const t = implementations[version]; + const func = t[funcName]; + const idObj = t.identifier("obj"); + const idProp = t.identifier("prop"); + suite.add(`${version} ${funcName} builder`, () => { + func(idObj, idProp, /*computed?*/ false, /*optional? missing*/); + }); + } +} + +benchCases({ baseline, current }); + +suite.on("cycle", report).run(); diff --git a/benchmark/babel-types/builders/stringLiteral.mjs b/benchmark/babel-types/builders/stringLiteral.mjs new file mode 100644 index 000000000000..bf1daf882d89 --- /dev/null +++ b/benchmark/babel-types/builders/stringLiteral.mjs @@ -0,0 +1,21 @@ +import Benchmark from "benchmark"; +import baseline from "@babel-baseline/types"; +import current from "@babel/types"; +import { report } from "../../util.mjs"; + +const suite = new Benchmark.Suite(); + +function benchCases(implementations) { + const funcName = "stringLiteral"; + for (const version in implementations) { + const t = implementations[version]; + const func = t[funcName]; + suite.add(`${version} ${funcName} builder`, () => { + func("bar"); + }); + } +} + +benchCases({ baseline, current }); + +suite.on("cycle", report).run(); diff --git a/benchmark/package.json b/benchmark/package.json index 52d46e582aad..adfa2d623258 100644 --- a/benchmark/package.json +++ b/benchmark/package.json @@ -8,6 +8,7 @@ "@babel-baseline/helper-validator-identifier": "npm:@babel/helper-validator-identifier@7.10.4", "@babel-baseline/parser": "npm:@babel/parser@7.14.8", "@babel-baseline/traverse": "npm:@babel/traverse@7.15.4", + "@babel-baseline/types": "npm:@babel/types@7.15.6", "@babel/core": "workspace:*", "@babel/generator": "workspace:*", "@babel/helper-validator-identifier": "workspace:*", @@ -15,6 +16,7 @@ "@babel/preset-env": "workspace:*", "@babel/preset-flow": "workspace:*", "@babel/traverse": "workspace:*", + "@babel/types": "workspace:*", "benchmark": "^2.1.4" }, "version": "7.15.0" diff --git a/yarn.lock b/yarn.lock index df0cdb0bceba..a014c25a5042 100644 --- a/yarn.lock +++ b/yarn.lock @@ -72,6 +72,16 @@ __metadata: languageName: node linkType: hard +"@babel-baseline/types@npm:@babel/types@7.15.6, @babel/types@npm:^7.0.0, @babel/types@npm:^7.12.7, @babel/types@npm:^7.14.5, @babel/types@npm:^7.15.0, @babel/types@npm:^7.15.4, @babel/types@npm:^7.15.6, @babel/types@npm:^7.3.3, @babel/types@npm:^7.4.4": + version: 7.15.6 + resolution: "@babel/types@npm:7.15.6" + dependencies: + "@babel/helper-validator-identifier": ^7.14.9 + to-fast-properties: ^2.0.0 + checksum: 37f497dde10d238b5eb184efab83b415a86611e3d73dc0434de0cfb851b20ee606a3b7e1525e5b2d522fac1248d0345fea0468006f246262511b80cd3ed2419f + languageName: node + linkType: hard + "@babel-internal/runtime-integration-rollup@workspace:test/runtime-integration/rollup": version: 0.0.0-use.local resolution: "@babel-internal/runtime-integration-rollup@workspace:test/runtime-integration/rollup" @@ -130,6 +140,7 @@ __metadata: "@babel-baseline/helper-validator-identifier": "npm:@babel/helper-validator-identifier@7.10.4" "@babel-baseline/parser": "npm:@babel/parser@7.14.8" "@babel-baseline/traverse": "npm:@babel/traverse@7.15.4" + "@babel-baseline/types": "npm:@babel/types@7.15.6" "@babel/core": "workspace:*" "@babel/generator": "workspace:*" "@babel/helper-validator-identifier": "workspace:*" @@ -137,6 +148,7 @@ __metadata: "@babel/preset-env": "workspace:*" "@babel/preset-flow": "workspace:*" "@babel/traverse": "workspace:*" + "@babel/types": "workspace:*" benchmark: ^2.1.4 languageName: unknown linkType: soft @@ -3600,16 +3612,6 @@ __metadata: languageName: unknown linkType: soft -"@babel/types@npm:^7.0.0, @babel/types@npm:^7.12.7, @babel/types@npm:^7.14.5, @babel/types@npm:^7.15.0, @babel/types@npm:^7.15.4, @babel/types@npm:^7.15.6, @babel/types@npm:^7.3.3, @babel/types@npm:^7.4.4": - version: 7.15.6 - resolution: "@babel/types@npm:7.15.6" - dependencies: - "@babel/helper-validator-identifier": ^7.14.9 - to-fast-properties: ^2.0.0 - checksum: 37f497dde10d238b5eb184efab83b415a86611e3d73dc0434de0cfb851b20ee606a3b7e1525e5b2d522fac1248d0345fea0468006f246262511b80cd3ed2419f - languageName: node - linkType: hard - "@babel/types@workspace:*, @babel/types@workspace:^7.14.9, @babel/types@workspace:^7.15.4, @babel/types@workspace:^7.15.6, @babel/types@workspace:packages/babel-types": version: 0.0.0-use.local resolution: "@babel/types@workspace:packages/babel-types"