diff --git a/.github/workflows/jmeter-benchmarking.yaml b/.github/workflows/jmeter-benchmarking.yaml index 454b624c0fb..b3b5b32dab4 100644 --- a/.github/workflows/jmeter-benchmarking.yaml +++ b/.github/workflows/jmeter-benchmarking.yaml @@ -1,4 +1,4 @@ -name: JMH Benchmark +name: Benchmark.js Example on: push: branches: @@ -13,22 +13,79 @@ permissions: jobs: benchmark: - name: Run JMH benchmark example + name: Run JavaScript benchmark example runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: actions/setup-java@v2 - with: - distribution: 'adopt' - java-version: '11' - - name: Cache SBT dependencies - uses: coursier/cache-action@v6 - - name: Build and run JMH benchmark - run: | - sbt clean compile - sbt 'benchmarks/jmh:run -i 1 -wi 0 -f1 -t1 -rf json -rff output.json .*' - - name: JMH Benchmark Action - uses: kitlangton/jmh-benchmark-action@main + - uses: actions/checkout@v2 + - uses: actions/setup-node@v1 + - name: Run benchmark + run: cd examples/benchmarkjs && npm install && node bench.js | tee output.txt + + - name: Store benchmark result + uses: benchmark-action/github-action-benchmark@v1 with: - jmh-output-path: benchmarks/output.json - github-token: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file + tool: 'benchmarkjs' + output-file-path: examples/benchmarkjs/output.txt + + # - name: Store benchmark result + # uses: benchmark-action/github-action-benchmark@v1 + # with: + # name: Benchmark.js Benchmark + # tool: 'benchmarkjs' + # output-file-path: examples/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: examples/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 + # alert-comment-cc-users: '@ktrz' + # gh-repository: 'github.com/benchmark-action/github-action-benchmark-results' + +# name: JMH Benchmark +# on: +# push: +# branches: +# - main +# pull_request: +# branches: +# - main + +# permissions: +# contents: write +# deployments: write + +# jobs: +# benchmark: +# name: Run JMH benchmark example +# runs-on: ubuntu-latest +# steps: +# - uses: actions/checkout@v3 +# - uses: actions/setup-java@v2 +# with: +# distribution: 'adopt' +# java-version: '11' +# - name: Cache SBT dependencies +# uses: coursier/cache-action@v6 +# - name: Build and run JMH benchmark +# run: | +# sbt clean compile +# sbt 'benchmarks/jmh:run -i 1 -wi 0 -f1 -t1 -rf json -rff output.json .*' +# - name: JMH Benchmark Action +# uses: kitlangton/jmh-benchmark-action@main +# with: +# jmh-output-path: benchmarks/output.json +# github-token: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/examples/benchmarkjs/.gitignore b/examples/benchmarkjs/.gitignore new file mode 100644 index 00000000000..49e0fc6b4d3 --- /dev/null +++ b/examples/benchmarkjs/.gitignore @@ -0,0 +1,2 @@ +/node_modules +/package-lock.json \ No newline at end of file diff --git a/examples/benchmarkjs/bench.js b/examples/benchmarkjs/bench.js new file mode 100644 index 00000000000..3af56c73e06 --- /dev/null +++ b/examples/benchmarkjs/bench.js @@ -0,0 +1,15 @@ +const Benchmark = require('benchmark'); +const suite = new Benchmark.Suite(); +const { fib } = require('./index'); + +suite + .add("fib(10)", () => { + fib(10); + }) + .add("fib(20)", () => { + fib(20); + }) + .on("cycle", (event) => { + console.log(String(event.target)); + }) + .run(); diff --git a/examples/benchmarkjs/index.js b/examples/benchmarkjs/index.js new file mode 100644 index 00000000000..b6508e2d830 --- /dev/null +++ b/examples/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; diff --git a/examples/benchmarkjs/package.json b/examples/benchmarkjs/package.json new file mode 100644 index 00000000000..42c54e40011 --- /dev/null +++ b/examples/benchmarkjs/package.json @@ -0,0 +1,15 @@ +{ + "name": "benchmark-example", + "private": true, + "version": "0.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "rhysd (https://rhysd.github.io/)", + "license": "MIT", + "devDependencies": { + "benchmark": "^2.1.4" + } + } \ No newline at end of file diff --git a/package.json b/package.json index c27cca1d6b4..f545a01cc81 100644 --- a/package.json +++ b/package.json @@ -74,7 +74,8 @@ "prettier": "prettier --write --config .prettierrc.js \"./**/src/main/json/openapi.json\"", "lerna-publish-canary": "lerna publish --canary --force-publish --dist-tag $(git branch --show-current) --preid $(git branch --show-current) --loglevel=silly", "prepare": "husky install", - "init-registries": "npm config set @iroha2:registry=https://nexus.iroha.tech/repository/npm-group/" + "init-registries": "npm config set @iroha2:registry=https://nexus.iroha.tech/repository/npm-group/", + "test": "echo \"Error: no test specified\" && exit 1" }, "resolutions": { "ansi-html": ">0.0.8", @@ -110,6 +111,7 @@ "@typescript-eslint/eslint-plugin": "6.4.0", "@typescript-eslint/parser": "6.4.0", "adm-zip": "0.5.10", + "benchmark": "^2.1.4", "buffer": "6.0.3", "cpy-cli": "4.2.0", "cross-env": "7.0.3",