From eaa1a4a113c44a1e00090c67754e65d5c705e289 Mon Sep 17 00:00:00 2001 From: Jason Jean Date: Mon, 27 Nov 2023 09:39:19 -0500 Subject: [PATCH] chore(repo): add benchmark to the pipeline (#20418) --- .circleci/config.yml | 9 +++ .nx/workflows/agents.yaml | 6 ++ package.json | 9 +-- pnpm-lock.yaml | 131 +++++++++++++++++++++++++++++++++-- tools/benchmark/benchmark.js | 6 ++ tools/benchmark/worker.js | 18 +++++ 6 files changed, 168 insertions(+), 11 deletions(-) create mode 100644 tools/benchmark/benchmark.js create mode 100644 tools/benchmark/worker.js diff --git a/.circleci/config.yml b/.circleci/config.yml index 053bfec73e..3e00fd4676 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -87,6 +87,7 @@ jobs: NX_E2E_RUN_E2E: 'true' NX_CI_EXECUTION_ENV: 'linux' steps: + - run: lscpu - checkout - run: npx nx-cloud@next start-ci-run --distributes-on="8 linux-medium" --stop-agents-after="e2e" - run: @@ -99,6 +100,9 @@ jobs: os: linux - nx/set-shas: main-branch-name: 'master' + - run: + name: Benchmark + command: node tools/benchmark/benchmark.js - run: name: Check Documentation command: pnpm nx documentation --no-dte @@ -161,6 +165,11 @@ jobs: command: | pnpm nx affected -t e2e-macos --parallel=1 --base=$NX_BASE --head=$NX_HEAD no_output_timeout: 45m + - run: + name: Close CI group + command: | + pnpm nx-cloud stop-all-agents + no_output_timeout: 45m # ------------------------- # WORKFLOWS(JOBS) diff --git a/.nx/workflows/agents.yaml b/.nx/workflows/agents.yaml index 94274547cf..97be10d530 100644 --- a/.nx/workflows/agents.yaml +++ b/.nx/workflows/agents.yaml @@ -16,6 +16,9 @@ launch-templates: NPM_CONFIG_PREFIX: '/home/workflows/.npm-global' NX_CLOUD_ACCESS_TOKEN: '{{secrets.NX_CLOUD_ACCESS_TOKEN}}' init-steps: + - name: LSCPU + script: | + lscpu - name: Checkout uses: 'nrwl/nx-cloud-workflows/v1.1/workflow-steps/checkout/main.yaml' @@ -53,3 +56,6 @@ launch-templates: - name: Load Cargo Env script: echo "PATH=$HOME/.cargo/bin:$PATH" >> $NX_CLOUD_ENV + + - name: Benchmark + script: node tools/benchmark/benchmark.js diff --git a/package.json b/package.json index d3eebc1c4f..5cddbf0310 100644 --- a/package.json +++ b/package.json @@ -60,15 +60,16 @@ "@nestjs/schematics": "^9.1.0", "@nestjs/swagger": "^6.0.0", "@nestjs/testing": "^9.0.0", - "@nuxt/kit": "^3.8.1", - "@nuxt/schema":"^3.8.1", "@ngrx/effects": "~17.0.0", "@ngrx/router-store": "~17.0.0", "@ngrx/store": "~17.0.0", + "@nuxt/kit": "^3.8.1", + "@nuxt/schema": "^3.8.1", "@nx/angular": "17.1.1", "@nx/cypress": "17.1.1", "@nx/devkit": "17.1.1", "@nx/esbuild": "17.1.1", + "@nx/eslint": "17.1.1", "@nx/eslint-plugin": "17.1.1", "@nx/jest": "17.1.1", "@nx/js": "17.1.1", @@ -150,6 +151,7 @@ "conventional-changelog-cli": "^2.0.23", "convert-source-map": "^2.0.0", "copy-webpack-plugin": "^10.2.4", + "cpu-benchmark": "^1.0.1", "css-minimizer-webpack-plugin": "^5.0.0", "cypress": "^13.0.0", "cytoscape": "^3.18.2", @@ -294,8 +296,7 @@ "webpack-subresource-integrity": "^5.1.0", "xstate": "4.34.0", "yargs": "^17.6.2", - "yargs-parser": "21.1.1", - "@nx/eslint": "17.1.1" + "yargs-parser": "21.1.1" }, "author": "Victor Savkin", "license": "MIT", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 46aa57adce..4c86f15757 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1,5 +1,9 @@ lockfileVersion: '6.0' +settings: + autoInstallPeers: true + excludeLinksFromLockfile: false + overrides: minimist: ^1.2.6 underscore: ^1.12.1 @@ -246,7 +250,7 @@ devDependencies: version: 9.1.6(@nestjs/common@9.1.6)(@nestjs/core@9.1.6) '@nestjs/schematics': specifier: ^9.1.0 - version: 9.1.0(chokidar@3.5.3)(typescript@4.9.4) + version: 9.1.0(typescript@5.2.2) '@nestjs/swagger': specifier: ^6.0.0 version: 6.1.3(@nestjs/common@9.1.6)(@nestjs/core@9.1.6)(reflect-metadata@0.1.13) @@ -526,6 +530,9 @@ devDependencies: copy-webpack-plugin: specifier: ^10.2.4 version: 10.2.4(webpack@5.88.0) + cpu-benchmark: + specifier: ^1.0.1 + version: 1.0.1 css-minimizer-webpack-plugin: specifier: ^5.0.0 version: 5.0.0(esbuild@0.19.5)(webpack@5.88.0) @@ -579,7 +586,7 @@ devDependencies: version: 2.14.0(eslint@8.48.0) eslint-plugin-import: specifier: 2.26.0 - version: 2.26.0(@typescript-eslint/parser@5.62.0)(eslint-import-resolver-typescript@3.5.2)(eslint@8.48.0) + version: 2.26.0(@typescript-eslint/parser@6.10.0)(eslint@8.48.0) eslint-plugin-jsx-a11y: specifier: 6.6.1 version: 6.6.1(eslint@8.48.0) @@ -6334,6 +6341,20 @@ packages: - chokidar dev: true + /@nestjs/schematics@9.1.0(typescript@5.2.2): + resolution: {integrity: sha512-/7CyMTnPJSK9/xD9CkCqwuHPOlHVlLC2RDnbdCJ7mIO07SdbBbY14msTqtYW9VRQtsjZPLh1GTChf7ryJUImwA==} + peerDependencies: + typescript: '>=4.3.5' + dependencies: + '@angular-devkit/core': 15.2.4(chokidar@3.5.3) + '@angular-devkit/schematics': 15.2.4(chokidar@3.5.3) + jsonc-parser: 3.2.0 + pluralize: 8.0.0 + typescript: 5.2.2 + transitivePeerDependencies: + - chokidar + dev: true + /@nestjs/swagger@6.1.3(@nestjs/common@9.1.6)(@nestjs/core@9.1.6)(reflect-metadata@0.1.13): resolution: {integrity: sha512-H9C/yRgLFb5QrAt6iGrYmIX9X7Q0zXkgZaTNUATljUBra+RCWrEUbLHBcGjTAOtcIyGV/vmyCLv68YSVcZoE0Q==} peerDependencies: @@ -6836,6 +6857,42 @@ packages: - typescript dev: true + /@nrwl/js@15.8.0(@swc-node/register@1.6.8)(@swc/core@1.3.86)(nx@15.8.0)(prettier@2.7.1)(typescript@5.2.2): + resolution: {integrity: sha512-l2Q7oFpzx6ul7G0nKpMkrvnIEaOY+X8fc2g2Db5WqpnnBdfkrtWXZPg/O4DQ1p9O6BXrZ+Q2AK9bfgnliiwyEg==} + dependencies: + '@babel/core': 7.22.9 + '@babel/plugin-proposal-class-properties': 7.18.6(@babel/core@7.22.9) + '@babel/plugin-proposal-decorators': 7.21.0(@babel/core@7.22.9) + '@babel/plugin-transform-runtime': 7.22.9(@babel/core@7.22.9) + '@babel/preset-env': 7.22.5(@babel/core@7.22.9) + '@babel/preset-typescript': 7.22.5(@babel/core@7.22.9) + '@babel/runtime': 7.22.6 + '@nrwl/devkit': 15.8.0(nx@15.8.0)(typescript@5.2.2) + '@nrwl/workspace': 15.8.0(@swc-node/register@1.6.8)(@swc/core@1.3.86)(eslint@8.48.0)(prettier@2.7.1)(typescript@5.2.2) + '@phenomnomnominal/tsquery': 4.1.1(typescript@5.2.2) + babel-plugin-const-enum: 1.2.0(@babel/core@7.22.9) + babel-plugin-macros: 2.8.0 + babel-plugin-transform-typescript-metadata: 0.3.2(@babel/core@7.22.9) + chalk: 4.1.2 + fast-glob: 3.2.7 + fs-extra: 11.1.1 + ignore: 5.2.4 + js-tokens: 4.0.0 + minimatch: 3.0.5 + source-map-support: 0.5.19 + tree-kill: 1.2.2 + tslib: 2.6.2 + transitivePeerDependencies: + - '@babel/traverse' + - '@swc-node/register' + - '@swc/core' + - debug + - nx + - prettier + - supports-color + - typescript + dev: true + /@nrwl/js@17.1.1(@swc-node/register@1.6.8)(@swc/core@1.3.86)(@types/node@18.16.9)(nx@17.1.1)(typescript@5.2.2)(verdaccio@5.15.4): resolution: {integrity: sha512-1w8M9am/OXFLhRFLi5jzwDm2RfIRtFeI4Oinuuam2sTjJ46BplRzRmszYnX25J0a1OHH1P/hgVKq4iHcKOo8nQ==} dependencies: @@ -6862,7 +6919,7 @@ packages: optional: true dependencies: '@nrwl/devkit': 15.8.0(nx@15.8.0)(typescript@5.2.2) - '@nrwl/js': 15.8.0(@swc-node/register@1.6.8)(@swc/core@1.3.86)(eslint@8.48.0)(nx@17.1.1)(prettier@2.7.1)(typescript@5.2.2) + '@nrwl/js': 15.8.0(@swc-node/register@1.6.8)(@swc/core@1.3.86)(nx@15.8.0)(prettier@2.7.1)(typescript@5.2.2) '@phenomnomnominal/tsquery': 4.1.1(typescript@5.2.2) eslint: 8.48.0 tmp: 0.2.1 @@ -14679,6 +14736,10 @@ packages: path-type: 4.0.0 dev: true + /cpu-benchmark@1.0.1: + resolution: {integrity: sha512-b6FmkWdWvwKySXIdMFjXqh9xkWl5MCDq5EZv26/PxzlSoY+/pugsA8wx2rUJ4/w7MhtU/GqmKmifr+uufgMFnw==} + dev: true + /create-require@1.1.1: resolution: {integrity: sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==} @@ -16186,6 +16247,35 @@ packages: - supports-color dev: true + /eslint-module-utils@2.7.4(@typescript-eslint/parser@6.10.0)(eslint-import-resolver-node@0.3.6)(eslint@8.48.0): + resolution: {integrity: sha512-j4GT+rqzCoRKHwURX7pddtIPGySnX9Si/cgMI5ztrcqOPtk5dDEeZ34CQVPphnqkJytlc97Vuk05Um2mJ3gEQA==} + engines: {node: '>=4'} + peerDependencies: + '@typescript-eslint/parser': '*' + eslint: '*' + eslint-import-resolver-node: '*' + eslint-import-resolver-typescript: '*' + eslint-import-resolver-webpack: '*' + peerDependenciesMeta: + '@typescript-eslint/parser': + optional: true + eslint: + optional: true + eslint-import-resolver-node: + optional: true + eslint-import-resolver-typescript: + optional: true + eslint-import-resolver-webpack: + optional: true + dependencies: + '@typescript-eslint/parser': 6.10.0(eslint@8.48.0)(typescript@5.2.2) + debug: 3.2.7(supports-color@8.1.1) + eslint: 8.48.0 + eslint-import-resolver-node: 0.3.6 + transitivePeerDependencies: + - supports-color + dev: true + /eslint-plugin-cypress@2.14.0(eslint@8.48.0): resolution: {integrity: sha512-eW6tv7iIg7xujleAJX4Ujm649Bf5jweqa4ObPEIuueYRyLZt7qXGWhCY/n4bfeFW/j6nQZwbIBHKZt6EKcL/cg==} peerDependencies: @@ -16226,6 +16316,37 @@ packages: - supports-color dev: true + /eslint-plugin-import@2.26.0(@typescript-eslint/parser@6.10.0)(eslint@8.48.0): + resolution: {integrity: sha512-hYfi3FXaM8WPLf4S1cikh/r4IxnO6zrhZbEGz2b660EJRbuxgpDS5gkCuYgGWg2xxh2rBuIr4Pvhve/7c31koA==} + engines: {node: '>=4'} + peerDependencies: + '@typescript-eslint/parser': '*' + eslint: ^2 || ^3 || ^4 || ^5 || ^6 || ^7.2.0 || ^8 + peerDependenciesMeta: + '@typescript-eslint/parser': + optional: true + dependencies: + '@typescript-eslint/parser': 6.10.0(eslint@8.48.0)(typescript@5.2.2) + array-includes: 3.1.6 + array.prototype.flat: 1.3.1 + debug: 2.6.9 + doctrine: 2.1.0 + eslint: 8.48.0 + eslint-import-resolver-node: 0.3.6 + eslint-module-utils: 2.7.4(@typescript-eslint/parser@6.10.0)(eslint-import-resolver-node@0.3.6)(eslint@8.48.0) + has: 1.0.3 + is-core-module: 2.11.0 + is-glob: 4.0.3 + minimatch: 3.1.2 + object.values: 1.1.6 + resolve: 1.22.1 + tsconfig-paths: 3.14.1 + transitivePeerDependencies: + - eslint-import-resolver-typescript + - eslint-import-resolver-webpack + - supports-color + dev: true + /eslint-plugin-jsx-a11y@6.6.1(eslint@8.48.0): resolution: {integrity: sha512-sXgFVNHiWffBq23uiS/JaP6eVR622DqwB4yTzKvGZGcPq6/yZ3WmOZfuBks/vHWo9GaFOqC2ZK4i6+C35knx7Q==} engines: {node: '>=4.0'} @@ -28992,7 +29113,3 @@ packages: /zwitch@2.0.4: resolution: {integrity: sha512-bXE4cR/kVZhKZX/RjPEflHaKVhUVl85noU3v6b8apfQEc1x4A+zBxjZ4lN8LqGd6WZ3dl98pY4o717VFmoPp+A==} dev: true - -settings: - autoInstallPeers: true - excludeLinksFromLockfile: false diff --git a/tools/benchmark/benchmark.js b/tools/benchmark/benchmark.js new file mode 100644 index 0000000000..2ca7088dd4 --- /dev/null +++ b/tools/benchmark/benchmark.js @@ -0,0 +1,6 @@ +const { exec } = require('child_process'); + +for (let i = 0; i < 3; i++) { + const cp = exec(`node ./tools/benchmark/worker.js test_${i}`); + cp.stdout.pipe(process.stdout); +} diff --git a/tools/benchmark/worker.js b/tools/benchmark/worker.js new file mode 100644 index 0000000000..689ebf176d --- /dev/null +++ b/tools/benchmark/worker.js @@ -0,0 +1,18 @@ +const { fib, dist } = require('cpu-benchmark'); + +const data = []; +const passes = 100; +for (let i = 0; i < passes; i++) { + const duration = fib(41); // Returns time required (ms) + // to calculate the 41. fibonacci number recursively. + const ops = dist(1000); // Returns the amount of operations + // (distance matrix calculations) in 1000ms + + data.push({ duration, ops }); +} + +const avgDuration = data.reduce((acc, d) => acc + d.duration, 0) / data.length; +const avgOps = data.reduce((acc, d) => acc + d.ops, 0) / data.length; + +console.log(avgDuration, `average duration over ${passes} passes`); // Average duration +console.log(avgOps, `average ops over ${passes} passes`); // Average ops