Skip to content

Commit

Permalink
Add workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
gkjohnson committed Aug 20, 2023
1 parent 1e5a0d5 commit 4ccb287
Show file tree
Hide file tree
Showing 3 changed files with 153 additions and 2 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/benchmark-report.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# This workflow will do a clean install of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: Build Examples

on:
pull_request:
paths:
- 'src/**'
- 'package.json'
- 'benchmark/**'

permissions:
contents: read

jobs:
benchmark:
name: PR Benchmark
runs-on: ubuntu-latest

steps:
- name: Git checkout
uses: actions/checkout@v2

- name: Use Node.js
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'

- name: Install
run: npm ci

- name: Run PR Benchmark
run: node ./benchmark/run-benchmark.js --json > pr-benchmark.json

- name: Checkout master
run: git checkout master

- name: Run Master Benchmark
run: node ./benchmark/run-benchmark.js --json > main-benchmark.json

- name: Log Difference
run: node ./benchmark/make-benchmark-log.js

106 changes: 106 additions & 0 deletions benchmark/make-bench-log.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import fs from 'fs';
import { fileURLToPath } from 'url';
import { dirname, join } from 'path';
import { pad } from './utils.js';

const __filename = fileURLToPath( import.meta.url );
const __dirname = dirname( __filename );

const prData = JSON.parse( fs.readFileSync( join( __dirname, '../pr-benchmark.json' ) ) );
const maData = JSON.parse( fs.readFileSync( join( __dirname, '../master-benchmark.json' ) ) );

const info = [];
let skipped = 0;
for ( let i = 0; i < prData.length; i ++ ) {

const prInfo = prData[ i ];
const maInfo = maData[ i ];
const key = prInfo.key.replace( /\t/g, ' ' );

if ( prInfo.key !== maInfo.key ) {

skipped ++;

}

if ( prInfo.key === '' ) {

continue;

}

if ( prInfo.value === null ) {

info.push( { key: key } );
continue;

}

const maValue = parseFloat( maInfo.value );
const prValue = parseFloat( prInfo.value );

const unit = maInfo.value.replace( /[\s\d\.]+/g, '' );
const delta = prValue - maValue;
const perc = delta / maValue;

info.push( {
key: key,
before: maValue,
after: prValue,
delta: delta,
perc: perc,
unit: unit,
} );

}

const isOverThreshold = v => v.perc && v.perc > 0.03;
info.forEach( v => {

if ( isOverThreshold( v ) ) {

const line = [
pad( v.key, 40 ),
pad( `${ v.before.toFixed( 4 ) } ${ v.unit }`, 15 ),
pad( `${ v.after.toFixed( 4 ) } ${ v.unit }`, 15 ),
pad( `${ v.delta.toFixed( 4 ) } ${ v.unit }`, 15 ),
pad( `${ ( 100 * v.perc ).toFixed( 3 ) } %`, 15 ),
];
console.log( line.join( '| ' ) );

}

} );

console.log();
console.log();
console.log();

info.forEach( v => {

let line = [
pad( v.key, 40 ),
pad( '', 15 ),
pad( '', 15 ),
pad( '', 15 ),
pad( '', 15 ),
];

if ( v.perc ) {

line = [
( isOverThreshold( v ) ? '* ' : ' ' ) + pad( v.key, 40 ),
pad( `${ v.before.toFixed( 4 ) } ${ v.unit }`, 15 ),
pad( `${ v.after.toFixed( 4 ) } ${ v.unit }`, 15 ),
pad( `${ v.delta.toFixed( 4 ) } ${ v.unit }`, 15 ),
pad( `${ ( 100 * v.perc ).toFixed( 3 ) } %`, 15 ),
];

}

console.log( line.join( '| ' ) );

} );

// console.log( JSON.stringify( info, null, '\t' ) );

4 changes: 2 additions & 2 deletions benchmark/run-benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ const box = new THREE.Box3();
box.min.set( - 1, - 1, - 1 );
box.min.set( 1, 1, 1 );

const intersectGeometry = new THREE.TorusBufferGeometry( 5, 5, 30, 10 );
const intersectGeometry = new THREE.TorusGeometry( 5, 5, 30, 10 );
const geomMat = new THREE.Matrix4().compose( new THREE.Vector3(), new THREE.Quaternion(), new THREE.Vector3( 0.1, 0.1, 0.1 ) );

const target1 = {};
const target2 = {};

const geometry = new THREE.TorusBufferGeometry( 5, 5, 700, 300 );
const geometry = new THREE.TorusGeometry( 5, 5, 700, 300 );
const mesh = new THREE.Mesh( geometry, new THREE.MeshBasicMaterial() );
const raycaster = new THREE.Raycaster();
raycaster.ray.origin.set( 10, 20, 30 );
Expand Down

0 comments on commit 4ccb287

Please sign in to comment.