From ea9b3e3c9f8db913e8f75656ad3f47d6fa303828 Mon Sep 17 00:00:00 2001 From: ruzell22 Date: Mon, 15 Jan 2024 08:39:56 +0800 Subject: [PATCH] Jmeterbenchmark test jmeter benchmarking Signed-off-by: ruzell22 --- .github/workflows/jmeter-benchmarking.yaml | 58 +++++++++++++++++++ .../src/test/benchmarkjs/.gitignore | 2 + .../src/test/benchmarkjs/bench.js | 31 ++++++++++ .../src/test/benchmarkjs/index.js | 8 +++ .../src/test/benchmarkjs/package.json | 0 5 files changed, 99 insertions(+) create mode 100644 .github/workflows/jmeter-benchmarking.yaml create mode 100644 packages/cactus-plugin-ledger-connector-besu/src/test/benchmarkjs/.gitignore create mode 100644 packages/cactus-plugin-ledger-connector-besu/src/test/benchmarkjs/bench.js create mode 100644 packages/cactus-plugin-ledger-connector-besu/src/test/benchmarkjs/index.js create mode 100644 packages/cactus-plugin-ledger-connector-besu/src/test/benchmarkjs/package.json diff --git a/.github/workflows/jmeter-benchmarking.yaml b/.github/workflows/jmeter-benchmarking.yaml new file mode 100644 index 00000000000..ebf426480a0 --- /dev/null +++ b/.github/workflows/jmeter-benchmarking.yaml @@ -0,0 +1,58 @@ +name: Benchmark.js Example +on: + push: + branches: + - main + pull_request: + branches: + - main + +permissions: + contents: write + deployments: write + +jobs: + benchmark: + name: Run JavaScript benchmark example + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v1 + - name: Run benchmark + run: cd packages/cactus-plugin-ledger-connector-besu/src/test/benchmarkjs && npm install && node bench.js | tee output.txt + + - name: Commit changes + run: | + git add packages/cactus-plugin-ledger-connector-besu/src/test/benchmarkjs/package.json + git commit -s -m "Committing changes to package.json" + if: github.event_name == 'push' + + - name: Stash changes + run: git stash + if: github.event_name == 'pull_request' + + - name: Store benchmark result + uses: benchmark-action/github-action-benchmark@v1 + with: + tool: 'benchmarkjs' + output-file-path: packages/cactus-plugin-ledger-connector-besu/src/test/benchmarkjs/output.txt + github-token: ${{ secrets.GITHUB_TOKEN }} + auto-push: true + # Show alert with commit comment on detecting possible performance regression + alert-threshold: '200%' + comment-on-alert: true + fail-on-alert: true + + # - name: Store benchmark result - separate results repo + # uses: benchmark-action/github-action-benchmark@v1 + # with: + # name: Benchmark.js Benchmark + # tool: 'benchmarkjs' + # output-file-path: packages/cactus-plugin-ledger-connector-besu/src/test/benchmarkjs/output.txt + # github-token: ${{ secrets.BENCHMARK_ACTION_BOT_TOKEN }} + # auto-push: true + # # Show alert with commit comment on detecting possible performance regression + # alert-threshold: '200%' + # comment-on-alert: true + # fail-on-alert: true + # gh-repository: 'github.com/benchmark-action/github-action-benchmark-results' \ No newline at end of file diff --git a/packages/cactus-plugin-ledger-connector-besu/src/test/benchmarkjs/.gitignore b/packages/cactus-plugin-ledger-connector-besu/src/test/benchmarkjs/.gitignore new file mode 100644 index 00000000000..49e0fc6b4d3 --- /dev/null +++ b/packages/cactus-plugin-ledger-connector-besu/src/test/benchmarkjs/.gitignore @@ -0,0 +1,2 @@ +/node_modules +/package-lock.json \ No newline at end of file diff --git a/packages/cactus-plugin-ledger-connector-besu/src/test/benchmarkjs/bench.js b/packages/cactus-plugin-ledger-connector-besu/src/test/benchmarkjs/bench.js new file mode 100644 index 00000000000..6ee6c20a32b --- /dev/null +++ b/packages/cactus-plugin-ledger-connector-besu/src/test/benchmarkjs/bench.js @@ -0,0 +1,31 @@ +const Benchmark = require('benchmark'); +const suite = new Benchmark.Suite(); +const { exec } = require('child_process'); +const benchmarkBesu = "benchmark-besu"; + +suite +exec(`npm run ${benchmarkBesu}`, (error, stdout) => { + if (error) { + console.error(); + return; + } + + on("cycle", (event) => { + console.log(String(event.target)); + }) + .run(); + +// console.log(`Script output:\n${stdout}`); +}); + +// suite +// .add("fib(10)", () => { +// fib(10); +// }) +// .add("fib(20)", () => { +// fib(20); +// }) +// .on("cycle", (event) => { +// console.log(String(event.target)); +// }) +// .run(); \ No newline at end of file diff --git a/packages/cactus-plugin-ledger-connector-besu/src/test/benchmarkjs/index.js b/packages/cactus-plugin-ledger-connector-besu/src/test/benchmarkjs/index.js new file mode 100644 index 00000000000..ca9bef62a1a --- /dev/null +++ b/packages/cactus-plugin-ledger-connector-besu/src/test/benchmarkjs/index.js @@ -0,0 +1,8 @@ +function fib(n) { + if (n <= 1) { + return 1; + } + return fib(n - 2) + fib(n - 1); + } + + exports.fib = fib; \ No newline at end of file diff --git a/packages/cactus-plugin-ledger-connector-besu/src/test/benchmarkjs/package.json b/packages/cactus-plugin-ledger-connector-besu/src/test/benchmarkjs/package.json new file mode 100644 index 00000000000..e69de29bb2d