-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optimization wollok game #328
base: master
Are you sure you want to change the base?
Changes from all commits
9ca1223
1cee6c3
a5ed7b8
41360de
a1c874e
5037bb5
a029e3d
9b264ba
f60e38c
dd12fe9
e916496
db4e5ed
b324001
cfb9fc9
d1ee6f6
dbe14b0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -113,7 +113,8 @@ | |
"time", | ||
"timeEnd", | ||
"group", | ||
"groupEnd" | ||
"groupEnd", | ||
"table" | ||
] | ||
} | ||
], | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
name: Run Benchmarks | ||
|
||
on: [pull_request] | ||
|
||
jobs: | ||
run-benchmarks: | ||
if: ${{ contains(github.event.pull_request.body, '[Run benchmarks]') }} | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
- name: Read .nvmrc | ||
run: echo "##[set-output name=NVMRC;]$(cat .nvmrc)" | ||
id: nvm | ||
- name: Use Node.js (.nvmrc) | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: "${{ steps.nvm.outputs.NVMRC }}" | ||
- name: Install dependencies | ||
run: npm install | ||
|
||
- name: Run benchmarks | ||
run: npm run test:benchmarks | tail -n +7 > bench-results.txt | ||
continue-on-error: true | ||
|
||
- name: Post results to comment | ||
uses: peter-evans/commit-comment@v3 | ||
with: | ||
body-path: 'bench-results.txt' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { should } from 'chai' | ||
import { resolve } from 'path' | ||
import { restore, stub } from 'sinon' | ||
import { PROGRAM_FILE_EXTENSION } from '../src' | ||
import { interpret } from '../src/interpreter/interpreter' | ||
import natives from '../src/wre/wre.natives' | ||
import { buildEnvironment } from './assertions' | ||
|
||
should() | ||
|
||
describe('Benchmarks', () => { | ||
const results: any[] = [] | ||
|
||
after(() => console.table(results)) | ||
|
||
describe('flushEvents', () => { | ||
|
||
function benchmark(fqn: string, expectedTime = 0) { | ||
it(fqn, async () => { | ||
stub(console) | ||
const iterations = 30 | ||
|
||
const program = `games.${fqn}` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. una pavada, pero no falta subir los programas? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Están en Language |
||
const message = 'flushEvents' | ||
|
||
let totalTime = 0 | ||
for (let index = 0; index < iterations; index++) | ||
totalTime += await measure(program, message) | ||
|
||
|
||
const time = totalTime / iterations | ||
const deltaError = expectedTime * 0.15 // 15 % | ||
restore() | ||
|
||
// console.info(`${message} - ${fqn} - ${time} ms (${iterations} iterations)`) | ||
results.push({ message, fqn, time, iterations }) | ||
time.should.be.closeTo(expectedTime, deltaError) | ||
}) | ||
} | ||
|
||
benchmark('empty', 6) | ||
benchmark('visuals_1', 4.5) | ||
benchmark('visuals_100', 4) | ||
benchmark('ticks_1', 12) | ||
benchmark('ticks_100', 637) | ||
benchmark('onCollide_1', 11) | ||
benchmark('onCollide_10_same_position', 5000) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Este caso se debería poder optimizar reutilizando la lista de colliders:
Ahora es medio paja hacerlo porque cada colisión es independiente del resto, habría que cambiar el modelo actual para centralizar el manejo de los colliders. Prefiero hacerlo en la próxima iteración. |
||
benchmark('onCollide_100_diff_positions', 675) | ||
|
||
}) | ||
}) | ||
|
||
async function measure(programFQN: string, message: string): Promise<number> { | ||
const environment = await buildEnvironment(`**/*.${PROGRAM_FILE_EXTENSION}`, resolve('language', 'benchmarks')) | ||
const interpreter = interpret(environment, natives) | ||
|
||
interpreter.run(programFQN) | ||
const game = interpreter.object('wollok.game.game') | ||
|
||
interpreter.send(message, game, interpreter.reify(0)) // Fill caches | ||
const startTime = performance.now() | ||
for (let ms = 1; ms < 10; ms++) | ||
interpreter.send(message, game, interpreter.reify(ms)) | ||
const endTime = performance.now() | ||
|
||
const elapsedTime = endTime - startTime | ||
return elapsedTime | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.